Skip to content

Commit 24c1f8d

Browse files
cweillclaude
andcommitted
Fix -template_params flag not being passed (Issue #149)
Resolves #149 The -template_params flag was defined in main.go but never passed to the process.Options struct, making it non-functional. This was a bug introduced in PR #90. Changes: - Added TemplateParams field to process.Options struct - Updated main.go to pass *templateParams to process.Run() - Updated process.go to parse JSON from TemplateParams string - File-based params (-template_params_file) take precedence over string-based params (-template_params) if both are provided - Added proper error handling for invalid JSON The flag now works as intended: $ gotests -template_params '{"key":"value"}' -all file.go Thanks to @butuzov for identifying this issue and @cweill for the fix suggestion! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 307a738 commit 24c1f8d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

gotests/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func main() {
101101
Template: valOrGetenv(*template, "GOTESTS_TEMPLATE"),
102102
TemplateDir: valOrGetenv(*templateDir, "GOTESTS_TEMPLATE_DIR"),
103103
TemplateParamsPath: *templateParamsPath,
104+
TemplateParams: *templateParams,
104105
UseGoCmp: *useGoCmp,
105106
})
106107
}

gotests/process/process.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Options struct {
3535
Template string // Name of custom template set
3636
TemplateDir string // Path to custom template set
3737
TemplateParamsPath string // Path to custom parameters json file(s).
38+
TemplateParams string // Custom parameters as JSON string
3839
TemplateData [][]byte // Data slice for templates
3940
UseGoCmp bool // Use cmp.Equal (google/go-cmp) instead of reflect.DeepEqual
4041
}
@@ -76,6 +77,17 @@ func parseOptions(out io.Writer, opt *Options) *gotests.Options {
7677
}
7778

7879
templateParams := map[string]interface{}{}
80+
81+
// Parse template params from JSON string if provided
82+
if opt.TemplateParams != "" {
83+
err := json.Unmarshal([]byte(opt.TemplateParams), &templateParams)
84+
if err != nil {
85+
fmt.Fprintf(out, "Failed to unmarshal template_params JSON: %s", err)
86+
return nil
87+
}
88+
}
89+
90+
// Parse template params from file if provided (takes precedence)
7991
jfile := opt.TemplateParamsPath
8092
if jfile != "" {
8193
buf, err := ioutil.ReadFile(jfile)

0 commit comments

Comments
 (0)