-
Notifications
You must be signed in to change notification settings - Fork 14
Add --var
template variable support to generate
command with command-specific reserved key validation
#83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --var
template variable support to generate
command with command-specific reserved key validation
#83
Conversation
Co-authored-by: pelikhan <[email protected]>
var
template variable support to generate command--var
template variable support to generate
command
Refactor the function to parse var string into a shared utility with the run command |
Co-authored-by: pelikhan <[email protected]>
Refactored the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
@@ -50,6 +52,12 @@ func NewGenerateCommand(cfg *command.Config) *cobra.Command { | |||
return fmt.Errorf("failed to parse flags: %w", err) | |||
} | |||
|
|||
// Parse template variables from flags | |||
templateVars, err := util.ParseTemplateVariables(cmd.Flags()) | |||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that "input" is not a template bars key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added validation to prevent "input" from being used as a template variable key. The util.ParseTemplateVariables
function now returns a clear error: "'input' is a reserved variable name and cannot be used with --var". This prevents conflicts with the built-in "input" variable used for backward compatibility. Commit: b01b3b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input is allowed for "run" command but not for "generate" command. Move the check to the generate command code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the "input" validation from the shared utility function to the generate command code. Now the run command allows "input" as a template variable while the generate command still prevents it to avoid conflicts with the built-in variable. Commit: 7a60a81
Co-authored-by: pelikhan <[email protected]>
--var
template variable support to generate
command--var
template variable support to generate
command with reserved key validation
Co-authored-by: pelikhan <[email protected]>
--var
template variable support to generate
command with reserved key validation--var
template variable support to generate
command with command-specific reserved key validation
This PR adds
--var
template variable support to thegenerate
command, matching the functionality already available in therun
command. This enables users to create flexible, reusable prompt files for test generation scenarios while preventing conflicts with reserved variables only where necessary.Problem
The
generate
command previously only supported a fixedinput
variable when templating prompt files, while therun
command supported custom template variables via--var name=value
flags. This inconsistency made it difficult to create reusable prompt templates for test generation.Solution
Added complete
--var
template variable support to thegenerate
command by:--var
flag can now be used multiple times to pass custom template variablesutil.ParseTemplateVariables()
function used by bothrun
andgenerate
commandsinput
from being used as a template variable key in thegenerate
command only to avoid conflicts with the built-in variablerunSingleTestWithContext()
input
variable is preserved alongside custom variablesUsage
Example prompt file with template variables:
Implementation Details
run
andgenerate
commands useutil.ParseTemplateVariables()
for consistent behaviorgenerate
command validates against using "input" as a template variable to prevent conflicts with its built-in variable{"input": inputValue, "name": "customValue", ...}
Testing
run
command accepts "input" as template variablegenerate
command rejects "input" as template variableThis change enables more flexible and parameterized prompt files for test generation while maintaining full backward compatibility and preventing variable conflicts only where necessary.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.