Skip to content

Commit 132868f

Browse files
committed
Add flags for template/YAML processing, update logs
1 parent 099002d commit 132868f

8 files changed

+230
-47
lines changed

cmd/list_metadata.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ var listMetadataCmd = &cobra.Command{
4141
func init() {
4242
fl.AddCommonListFlags(listMetadataCmd)
4343

44+
// Add template and function processing flags
45+
listMetadataCmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing in Atmos stack manifests when executing the command")
46+
listMetadataCmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing in Atmos stack manifests when executing the command")
47+
4448
AddStackCompletion(listMetadataCmd)
4549

4650
listCmd.AddCommand(listMetadataCmd)
@@ -55,6 +59,23 @@ func listMetadata(cmd *cobra.Command) (string, error) {
5559
}
5660
}
5761

62+
// Get template and function processing flags
63+
processTemplates := true
64+
if cmd.Flags().Lookup("process-templates") != nil {
65+
processTemplates, err = cmd.Flags().GetBool("process-templates")
66+
if err != nil {
67+
log.Warn("failed to get process-templates flag, using default true", "error", err)
68+
}
69+
}
70+
71+
processYamlFunctions := true
72+
if cmd.Flags().Lookup("process-functions") != nil {
73+
processYamlFunctions, err = cmd.Flags().GetBool("process-functions")
74+
if err != nil {
75+
log.Warn("failed to get process-functions flag, using default true", "error", err)
76+
}
77+
}
78+
5879
if f.Format(commonFlags.Format) == f.FormatCSV && commonFlags.Delimiter == f.DefaultTSVDelimiter {
5980
commonFlags.Delimiter = f.DefaultCSVDelimiter
6081
}
@@ -67,11 +88,20 @@ func listMetadata(cmd *cobra.Command) (string, error) {
6788
}
6889

6990
// Get all stacks
70-
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, false, false, false, nil)
91+
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, processTemplates, processYamlFunctions, false, nil)
7192
if err != nil {
7293
return "", &errors.DescribeStacksError{Cause: err}
7394
}
7495

96+
// Log the metadata query
97+
log.Info("Filtering metadata",
98+
"query", commonFlags.Query,
99+
"maxColumns", commonFlags.MaxColumns,
100+
"format", commonFlags.Format,
101+
"stackPattern", commonFlags.Stack,
102+
"processTemplates", processTemplates,
103+
"processYamlFunctions", processYamlFunctions)
104+
75105
// Use .metadata as the default query if none provided
76106
if commonFlags.Query == "" {
77107
commonFlags.Query = ".metadata"

cmd/list_settings.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ var listSettingsCmd = &cobra.Command{
4141
func init() {
4242
fl.AddCommonListFlags(listSettingsCmd)
4343

44+
// Add template and function processing flags
45+
listSettingsCmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing in Atmos stack manifests when executing the command")
46+
listSettingsCmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing in Atmos stack manifests when executing the command")
47+
4448
AddStackCompletion(listSettingsCmd)
4549

4650
listCmd.AddCommand(listSettingsCmd)
@@ -53,6 +57,23 @@ func listSettings(cmd *cobra.Command) (string, error) {
5357
return "", &errors.CommonFlagsError{Cause: err}
5458
}
5559

60+
// Get template and function processing flags
61+
processTemplates := true
62+
if cmd.Flags().Lookup("process-templates") != nil {
63+
processTemplates, err = cmd.Flags().GetBool("process-templates")
64+
if err != nil {
65+
log.Warn("failed to get process-templates flag, using default true", "error", err)
66+
}
67+
}
68+
69+
processYamlFunctions := true
70+
if cmd.Flags().Lookup("process-functions") != nil {
71+
processYamlFunctions, err = cmd.Flags().GetBool("process-functions")
72+
if err != nil {
73+
log.Warn("failed to get process-functions flag, using default true", "error", err)
74+
}
75+
}
76+
5677
if f.Format(commonFlags.Format) == f.FormatCSV && commonFlags.Delimiter == f.DefaultTSVDelimiter {
5778
commonFlags.Delimiter = f.DefaultCSVDelimiter
5879
}
@@ -65,11 +86,20 @@ func listSettings(cmd *cobra.Command) (string, error) {
6586
}
6687

6788
// Get all stacks
68-
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, false, false, false, nil)
89+
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, processTemplates, processYamlFunctions, false, nil)
6990
if err != nil {
7091
return "", &errors.DescribeStacksError{Cause: err}
7192
}
7293

94+
// Log the settings query
95+
log.Info("Filtering settings",
96+
"query", commonFlags.Query,
97+
"maxColumns", commonFlags.MaxColumns,
98+
"format", commonFlags.Format,
99+
"stackPattern", commonFlags.Stack,
100+
"processTemplates", processTemplates,
101+
"processYamlFunctions", processYamlFunctions)
102+
73103
// Use empty query to avoid further processing since handleComponentProperties will extract the settings
74104
output, err := l.FilterAndListValues(stacksMap, &l.FilterOptions{
75105
Component: "settings",

cmd/list_values.go

+85-31
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ var (
2323
ErrGettingVarsFlag = errors.New("error getting vars flag")
2424
ErrInitializingCLIConfig = errors.New("error initializing CLI config")
2525
ErrDescribingStacks = errors.New("error describing stacks")
26+
ErrComponentNameRequired = errors.New("component name is required")
2627
)
2728

2829
// Error format strings.
2930
const (
3031
ErrFmtWrapErr = "%w: %v" // Format for wrapping errors.
3132
)
3233

34+
// ProcessingOptions holds flags for processing templates and YAML functions.
35+
type ProcessingOptions struct {
36+
Templates bool
37+
Functions bool
38+
}
39+
3340
// listValuesCmd lists component values across stacks.
3441
var listValuesCmd = &cobra.Command{
3542
Use: "values [component]",
@@ -88,7 +95,9 @@ var listVarsCmd = &cobra.Command{
8895
strings.Contains(err.Error(), "query '.vars'") &&
8996
len(args) > 0 {
9097
// Replace with a more descriptive error
91-
log.Error(fmt.Sprintf("no values found for component '%s' with query '.vars'", args[0]))
98+
log.Error("no values found for component with query",
99+
"component", args[0],
100+
"query", ".vars")
92101
return
93102
}
94103
log.Error(err.Error())
@@ -109,6 +118,8 @@ func init() {
109118
// Add additional flags
110119
listValuesCmd.PersistentFlags().Bool("abstract", false, "Include abstract components")
111120
listValuesCmd.PersistentFlags().Bool("vars", false, "Show only vars (equivalent to `--query .vars`)")
121+
listValuesCmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing in Atmos stack manifests when executing the command")
122+
listValuesCmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing in Atmos stack manifests when executing the command")
112123

113124
// Add common flags to vars command
114125
fl.AddCommonListFlags(listVarsCmd)
@@ -118,6 +129,8 @@ func init() {
118129

119130
// Add abstract flag to vars command
120131
listVarsCmd.PersistentFlags().Bool("abstract", false, "Include abstract components")
132+
listVarsCmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing in Atmos stack manifests when executing the command")
133+
listVarsCmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing in Atmos stack manifests when executing the command")
121134

122135
// Add stack pattern completion
123136
AddStackCompletion(listValuesCmd)
@@ -128,45 +141,88 @@ func init() {
128141
listCmd.AddCommand(listVarsCmd)
129142
}
130143

131-
func listValues(cmd *cobra.Command, args []string) (string, error) {
144+
// getBoolFlagWithDefault gets a boolean flag value or returns the default if error.
145+
func getBoolFlagWithDefault(cmd *cobra.Command, flagName string, defaultValue bool) bool {
146+
if cmd.Flags().Lookup(flagName) == nil {
147+
return defaultValue
148+
}
149+
150+
value, err := cmd.Flags().GetBool(flagName)
151+
if err != nil {
152+
log.Warn("failed to get flag, using default",
153+
"flag", flagName,
154+
"default", defaultValue,
155+
"error", err)
156+
return defaultValue
157+
}
158+
159+
return value
160+
}
161+
162+
// getProcessingFlags gets template and function processing flags.
163+
func getProcessingFlags(cmd *cobra.Command) ProcessingOptions {
164+
return ProcessingOptions{
165+
Templates: getBoolFlagWithDefault(cmd, "process-templates", true),
166+
Functions: getBoolFlagWithDefault(cmd, "process-functions", true),
167+
}
168+
}
169+
170+
// getListValuesFlags extracts and processes all flags needed for list values command.
171+
func getListValuesFlags(cmd *cobra.Command) (*l.FilterOptions, ProcessingOptions, error) {
132172
// Get common flags
133173
commonFlags, err := fl.GetCommonListFlags(cmd)
134174
if err != nil {
135-
return "", fmt.Errorf(ErrFmtWrapErr, ErrGettingCommonFlags, err)
175+
return nil, ProcessingOptions{}, fmt.Errorf(ErrFmtWrapErr, ErrGettingCommonFlags, err)
136176
}
137177

138178
// Get additional flags
139179
abstractFlag, err := cmd.Flags().GetBool("abstract")
140180
if err != nil {
141-
return "", fmt.Errorf(ErrFmtWrapErr, ErrGettingAbstractFlag, err)
181+
return nil, ProcessingOptions{}, fmt.Errorf(ErrFmtWrapErr, ErrGettingAbstractFlag, err)
142182
}
143183

144-
// Get vars flag if it exists
145-
varsFlag := false
146-
if cmd.Flags().Lookup("vars") != nil {
147-
varsFlag, err = cmd.Flags().GetBool("vars")
148-
if err != nil {
149-
return "", fmt.Errorf(ErrFmtWrapErr, ErrGettingVarsFlag, err)
150-
}
184+
// Get vars flag and adjust query if needed
185+
varsFlag := getBoolFlagWithDefault(cmd, "vars", false)
186+
if varsFlag {
187+
commonFlags.Query = ".vars"
151188
}
152189

153190
// Set appropriate default delimiter based on format
154191
if f.Format(commonFlags.Format) == f.FormatCSV && commonFlags.Delimiter == f.DefaultTSVDelimiter {
155192
commonFlags.Delimiter = f.DefaultCSVDelimiter
156193
}
157194

158-
// If vars flag is set, override query
159-
if varsFlag {
160-
commonFlags.Query = ".vars"
195+
// Get processing flags
196+
processingOpts := getProcessingFlags(cmd)
197+
198+
filterOptions := &l.FilterOptions{
199+
Query: commonFlags.Query,
200+
IncludeAbstract: abstractFlag,
201+
MaxColumns: commonFlags.MaxColumns,
202+
FormatStr: commonFlags.Format,
203+
Delimiter: commonFlags.Delimiter,
204+
StackPattern: commonFlags.Stack,
161205
}
162206

207+
return filterOptions, processingOpts, nil
208+
}
209+
210+
func listValues(cmd *cobra.Command, args []string) (string, error) {
163211
// Ensure we have a component name
164212
if len(args) == 0 {
165-
return "", fmt.Errorf("component name is required")
213+
return "", ErrComponentNameRequired
166214
}
167-
168215
component := args[0]
169216

217+
// Get all flags and options
218+
filterOptions, processingOpts, err := getListValuesFlags(cmd)
219+
if err != nil {
220+
return "", err
221+
}
222+
223+
// Set component in filter options
224+
filterOptions.Component = component
225+
170226
// Log the component name
171227
log.Debug("Processing component", "component", component)
172228

@@ -178,24 +234,22 @@ func listValues(cmd *cobra.Command, args []string) (string, error) {
178234
}
179235

180236
// Get all stacks
181-
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, false, false, false, nil)
237+
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, processingOpts.Templates, processingOpts.Functions, false, nil)
182238
if err != nil {
183239
return "", fmt.Errorf(ErrFmtWrapErr, ErrDescribingStacks, err)
184240
}
185241

186-
// Filter and list component values across stacks
187-
output, err := l.FilterAndListValues(stacksMap, &l.FilterOptions{
188-
Component: component,
189-
Query: commonFlags.Query,
190-
IncludeAbstract: abstractFlag,
191-
MaxColumns: commonFlags.MaxColumns,
192-
FormatStr: commonFlags.Format,
193-
Delimiter: commonFlags.Delimiter,
194-
StackPattern: commonFlags.Stack,
195-
})
196-
if err != nil {
197-
return "", err // Return error directly without wrapping
198-
}
242+
// Log the filter options
243+
log.Info("Filtering values",
244+
"component", component,
245+
"query", filterOptions.Query,
246+
"includeAbstract", filterOptions.IncludeAbstract,
247+
"maxColumns", filterOptions.MaxColumns,
248+
"format", filterOptions.FormatStr,
249+
"stackPattern", filterOptions.StackPattern,
250+
"processTemplates", processingOpts.Templates,
251+
"processYamlFunctions", processingOpts.Functions)
199252

200-
return output, nil
253+
// Filter and list component values across stacks
254+
return l.FilterAndListValues(stacksMap, filterOptions)
201255
}

cmd/list_values_internal_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func TestListValuesFlags(t *testing.T) {
2323
cmd.PersistentFlags().Int("max-columns", 0, "Maximum columns")
2424
cmd.PersistentFlags().Bool("abstract", false, "Include abstract components")
2525
cmd.PersistentFlags().Bool("vars", false, "Show only vars")
26+
cmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing")
27+
cmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing")
2628

2729
formatFlag := cmd.PersistentFlags().Lookup("format")
2830
assert.NotNil(t, formatFlag, "Expected format flag to exist")
@@ -51,6 +53,14 @@ func TestListValuesFlags(t *testing.T) {
5153
varsFlag := cmd.PersistentFlags().Lookup("vars")
5254
assert.NotNil(t, varsFlag, "Expected vars flag to exist")
5355
assert.Equal(t, "false", varsFlag.DefValue)
56+
57+
processTemplatesFlag := cmd.PersistentFlags().Lookup("process-templates")
58+
assert.NotNil(t, processTemplatesFlag, "Expected process-templates flag to exist")
59+
assert.Equal(t, "true", processTemplatesFlag.DefValue)
60+
61+
processFunctionsFlag := cmd.PersistentFlags().Lookup("process-functions")
62+
assert.NotNil(t, processFunctionsFlag, "Expected process-functions flag to exist")
63+
assert.Equal(t, "true", processFunctionsFlag.DefValue)
5464
}
5565

5666
// TestListVarsFlags tests that the list vars command has the correct flags.
@@ -68,6 +78,8 @@ func TestListVarsFlags(t *testing.T) {
6878
cmd.PersistentFlags().String("query", "", "JQ query")
6979
cmd.PersistentFlags().Int("max-columns", 0, "Maximum columns")
7080
cmd.PersistentFlags().Bool("abstract", false, "Include abstract components")
81+
cmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing")
82+
cmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing")
7183

7284
assert.Equal(t, "vars [component]", cmd.Use)
7385
assert.Contains(t, cmd.Short, "List component vars across stacks")
@@ -96,6 +108,14 @@ func TestListVarsFlags(t *testing.T) {
96108
abstractFlag := cmd.PersistentFlags().Lookup("abstract")
97109
assert.NotNil(t, abstractFlag, "Expected abstract flag to exist")
98110
assert.Equal(t, "false", abstractFlag.DefValue)
111+
112+
processTemplatesFlag := cmd.PersistentFlags().Lookup("process-templates")
113+
assert.NotNil(t, processTemplatesFlag, "Expected process-templates flag to exist")
114+
assert.Equal(t, "true", processTemplatesFlag.DefValue)
115+
116+
processFunctionsFlag := cmd.PersistentFlags().Lookup("process-functions")
117+
assert.NotNil(t, processFunctionsFlag, "Expected process-functions flag to exist")
118+
assert.Equal(t, "true", processFunctionsFlag.DefValue)
99119
}
100120

101121
// TestListValuesValidatesArgs tests that the command validates arguments.

cmd/markdown/atmos_list_metadata_usage.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
$ atmos list metadata
44
```
55

6-
– List metadata for specific stacks
6+
– List specific metadata
77
```
8-
$ atmos list metadata --stack '*-dev-*'
8+
$ atmos list metadata --query '.component'
99
```
1010

11-
List specific metadata fields
11+
Filter by stack pattern
1212
```
13-
$ atmos list metadata --query .metadata.component
14-
$ atmos list metadata --query .metadata.type
13+
$ atmos list metadata --stack '*-dev-*'
1514
```
1615

1716
– Output in different formats
@@ -22,7 +21,14 @@
2221
$ atmos list metadata --format tsv
2322
```
2423

25-
– Filter by stack and specific metadata
24+
– Disable Go template processing
25+
```
26+
$ atmos list metadata --process-templates=false
27+
```
28+
29+
– Disable YAML functions processing
2630
```
27-
$ atmos list metadata --stack '*-ue2-*' --query .metadata.version
31+
$ atmos list metadata --process-functions=false
2832
```
33+
34+
- Stack patterns support glob matching (e.g., `*-dev-*`, `prod-*`, `*-{dev,staging}-*`)

0 commit comments

Comments
 (0)