mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 18:29:53 +00:00
added --values and --set flags to lint command (#1907)
* added --values and --set flags to lint command * Update lint_test.go
This commit is contained in:
@@ -88,7 +88,7 @@ func extractDocs(templateFiles []string, valuesFiles []string, setValues []strin
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to load values file %s", valuesFile)
|
||||
}
|
||||
values = mergeMaps(values, fileValues)
|
||||
values = preflight.MergeMaps(values, fileValues)
|
||||
}
|
||||
|
||||
// Normalize maps for Helm set merging
|
||||
@@ -331,25 +331,6 @@ func setNestedValue(m map[string]interface{}, keys []string, value interface{})
|
||||
}
|
||||
}
|
||||
|
||||
func mergeMaps(base, overlay map[string]interface{}) map[string]interface{} {
|
||||
result := make(map[string]interface{})
|
||||
for k, v := range base {
|
||||
result[k] = v
|
||||
}
|
||||
for k, v := range overlay {
|
||||
if baseVal, exists := result[k]; exists {
|
||||
if baseMap, ok := baseVal.(map[string]interface{}); ok {
|
||||
if overlayMap, ok := v.(map[string]interface{}); ok {
|
||||
result[k] = mergeMaps(baseMap, overlayMap)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
result[k] = v
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func renderTemplate(templateContent string, values map[string]interface{}) (string, error) {
|
||||
tmpl := template.New("preflight").Funcs(sprig.FuncMap())
|
||||
tmpl, err := tmpl.Parse(templateContent)
|
||||
|
||||
@@ -54,9 +54,11 @@ Exit codes:
|
||||
v := viper.GetViper()
|
||||
|
||||
opts := lint.LintOptions{
|
||||
FilePaths: args,
|
||||
Fix: v.GetBool("fix"),
|
||||
Format: v.GetString("format"),
|
||||
FilePaths: args,
|
||||
Fix: v.GetBool("fix"),
|
||||
Format: v.GetString("format"),
|
||||
ValuesFiles: v.GetStringSlice("values"),
|
||||
SetValues: v.GetStringSlice("set"),
|
||||
}
|
||||
|
||||
return runLint(opts)
|
||||
@@ -65,6 +67,8 @@ Exit codes:
|
||||
|
||||
cmd.Flags().Bool("fix", false, "Automatically fix issues where possible")
|
||||
cmd.Flags().String("format", "text", "Output format: text or json")
|
||||
cmd.Flags().StringSlice("values", []string{}, "Path to YAML files with template values (required for v1beta3 specs)")
|
||||
cmd.Flags().StringSlice("set", []string{}, "Set template values via command line (e.g., --set key=value)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -54,9 +54,11 @@ Exit codes:
|
||||
v := viper.GetViper()
|
||||
|
||||
opts := lint.LintOptions{
|
||||
FilePaths: args,
|
||||
Fix: v.GetBool("fix"),
|
||||
Format: v.GetString("format"),
|
||||
FilePaths: args,
|
||||
Fix: v.GetBool("fix"),
|
||||
Format: v.GetString("format"),
|
||||
ValuesFiles: v.GetStringSlice("values"),
|
||||
SetValues: v.GetStringSlice("set"),
|
||||
}
|
||||
|
||||
return runLint(opts)
|
||||
@@ -65,6 +67,8 @@ Exit codes:
|
||||
|
||||
cmd.Flags().Bool("fix", false, "Automatically fix issues where possible")
|
||||
cmd.Flags().String("format", "text", "Output format: text or json")
|
||||
cmd.Flags().StringSlice("values", []string{}, "Path to YAML files with template values (required for v1beta3 specs)")
|
||||
cmd.Flags().StringSlice("set", []string{}, "Set template values via command line (e.g., --set key=value)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user