Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
2e1e51d
feat: add `list values` command to compare component configurations a…
Cerebrovinny Feb 7, 2025
547f984
feat: add TSV format support for workflow listing
Cerebrovinny Feb 7, 2025
917cdd0
wip
Cerebrovinny Feb 7, 2025
72a8e76
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 7, 2025
b6b19b2
Merge branch 'main' into DEV-2802
Cerebrovinny Feb 13, 2025
30e14d0
update list values
Cerebrovinny Feb 11, 2025
f3db126
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 14, 2025
54d8ad0
fixes and clean up
Cerebrovinny Feb 14, 2025
b03b3c2
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 14, 2025
cc9c8bf
update terminal
Cerebrovinny Feb 14, 2025
9060a00
test list values
Cerebrovinny Feb 14, 2025
79e94f8
Update website/docs/cli/commands/list/list-values.mdx
Cerebrovinny Feb 15, 2025
cfec6fb
Add markdown docs for listing values/vars; update examples
Cerebrovinny Feb 15, 2025
df4c494
Add logger, replace error prints with log calls
Cerebrovinny Feb 15, 2025
872d881
Refactor imports and rename logger variable
Cerebrovinny Feb 15, 2025
368d21d
Handle 'no values found' error; improve logging logic
Cerebrovinny Feb 15, 2025
6a3e02b
Improve error messages with colored output
Cerebrovinny Feb 16, 2025
538d6b7
Add expectedError field to test cases for error validation
Cerebrovinny Feb 16, 2025
216e6cd
Merge branch 'main' into DEV-2802
Cerebrovinny Feb 17, 2025
6d87e2c
Refactor error handling, add custom error type
Cerebrovinny Feb 17, 2025
befa005
Refactor error handling, update TTY check logic
Cerebrovinny Feb 17, 2025
f07cb4a
Refactor commands to list metadata and settings
Cerebrovinny Feb 17, 2025
132dfce
general fixes
Cerebrovinny Feb 17, 2025
52f11fb
Remove unused getMapKeys function
Cerebrovinny Feb 17, 2025
ab3bde4
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 17, 2025
948a3c0
Merge branch 'main' into DEV-2802
Cerebrovinny Feb 18, 2025
1ce3cf4
Merge branch 'main' into DEV-2802
Cerebrovinny Feb 18, 2025
571d382
Merge branch 'main' into DEV-2802
Cerebrovinny Feb 19, 2025
9b72518
Switch to charmbracelet/log, remove custom logger setup
Cerebrovinny Feb 19, 2025
f4779cc
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 19, 2025
7d92050
Remove examples from command help, update markdown docs
Cerebrovinny Feb 19, 2025
4e758fc
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Feb 19, 2025
a2f790c
Merge branch 'main' into DEV-2802
Cerebrovinny Feb 19, 2025
d0e24c3
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 19, 2025
53f83ab
Refactor error logging, simplify path conversion
Cerebrovinny Feb 20, 2025
e0ec172
Merge branch 'main' into DEV-2802
Cerebrovinny Feb 20, 2025
a8af871
Merge branch 'main' into DEV-2802
osterman Feb 20, 2025
de1e0e2
Refactor imports, improve error logging
Cerebrovinny Feb 22, 2025
5fbaeef
Refactor list commands, add common flags & error handling
Cerebrovinny Feb 24, 2025
cc864f6
clean up
Cerebrovinny Feb 24, 2025
936bb93
Update website/docs/cli/commands/list/list-metadata.mdx
Cerebrovinny Feb 24, 2025
74842b7
Improve list commands & table formatting
Cerebrovinny Feb 24, 2025
9017862
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 24, 2025
e45f2ff
Update website/docs/cli/commands/list/list-settings.mdx
Cerebrovinny Feb 25, 2025
e3d0c38
Update query docs and linter configuration
Cerebrovinny Feb 25, 2025
1de71b5
Improve table and delimited formatter
Cerebrovinny Feb 25, 2025
9be83fa
refactor and clean up
Cerebrovinny Feb 25, 2025
cf17568
lint static fixes
Cerebrovinny Feb 25, 2025
735f339
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 25, 2025
ae180a2
fixes lint static check
Cerebrovinny Feb 25, 2025
67b8ce4
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 25, 2025
47ecda6
fixes lint static check
Cerebrovinny Feb 25, 2025
404f398
lint fixes
Cerebrovinny Feb 25, 2025
feeecdd
clean up the processcustomcommands is already on process command aliases
Cerebrovinny Feb 25, 2025
153a751
chore: update tests
Cerebrovinny Feb 25, 2025
4fa3270
disable vendor pull tests
Cerebrovinny Feb 25, 2025
7773a61
fix: unix line break windows
Cerebrovinny Feb 25, 2025
725825e
Update website/docs/cli/commands/list/list-metadata.mdx
Cerebrovinny Feb 25, 2025
38c14d3
Update website/docs/cli/commands/list/list-settings.mdx
Cerebrovinny Feb 25, 2025
a4ab6ea
Update cmd/markdown/atmos_list_vars_usage.md
Cerebrovinny Feb 25, 2025
4a69ea0
Update cmd/markdown/atmos_list_values_usage.md
Cerebrovinny Feb 25, 2025
7d0c33d
Update cmd/list_metadata.go
Cerebrovinny Feb 25, 2025
86aef46
Update website/docs/cli/commands/list/list-settings.mdx
Cerebrovinny Feb 25, 2025
2814f90
Update website/docs/cli/commands/list/list-settings.mdx
Cerebrovinny Feb 25, 2025
a042ce4
Update website/docs/cli/commands/list/list-metadata.mdx
Cerebrovinny Feb 25, 2025
fbec33d
fix: tests improvements
Cerebrovinny Feb 25, 2025
9eb34d2
fix: delimited
Cerebrovinny Feb 25, 2025
487bfef
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 25, 2025
0cf853b
disable vendor
Cerebrovinny Feb 26, 2025
d490867
Update pkg/utils/wildcard.go
Cerebrovinny Feb 26, 2025
89accc3
fix: fixes build
Cerebrovinny Feb 26, 2025
e781fb5
disable vendor
Cerebrovinny Feb 26, 2025
31e9b74
fix: disable more oci tests
Cerebrovinny Feb 26, 2025
19b252b
fix: disable more oci tests
Cerebrovinny Feb 26, 2025
51681d4
Merge branch 'main' into DEV-2802
osterman Feb 27, 2025
9c17849
Merge branch 'main' into DEV-2802
osterman Feb 28, 2025
90333d4
Merge branch 'main' into DEV-2802
osterman Feb 28, 2025
42e2d7b
Merge branch 'main' into DEV-2802
osterman Mar 2, 2025
ab7dcd5
fixes and increase extract coverage
Cerebrovinny Mar 3, 2025
bd8e4e8
Merge branch 'main' into DEV-2802
osterman Mar 3, 2025
1345a7b
Add tests for common list flags handling
Cerebrovinny Mar 3, 2025
5517e7b
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Mar 3, 2025
078575d
Refactor funcs, add tests for error handling
Cerebrovinny Mar 3, 2025
e63ea78
Merge branch 'main' into DEV-2802
osterman Mar 4, 2025
991a0af
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 4, 2025
c12fd07
Add internal tests for list metadata command
Cerebrovinny Mar 4, 2025
4f56434
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 4, 2025
e3b9b6e
Add tests for list values and vars command flags
Cerebrovinny Mar 4, 2025
8bcf2fc
added test for json formatter error coverage
Cerebrovinny Mar 4, 2025
a03494f
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 4, 2025
c12ae08
Add error checks for io.Copy in tests
Cerebrovinny Mar 5, 2025
f1c3490
Refactor error handling in test functions
Cerebrovinny Mar 5, 2025
d142019
Add periods to comments for consistency.
Cerebrovinny Mar 5, 2025
55a4f82
Add tests for error handling and CSV delimiter logic
Cerebrovinny Mar 5, 2025
feb94ff
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 5, 2025
6782e49
Refactor error handling, use static errors for tests
Cerebrovinny Mar 5, 2025
f632d6e
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 5, 2025
62de78b
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 7, 2025
99dc4dd
Merge branch 'main' into DEV-2802
osterman Mar 7, 2025
1bbf67c
Merge branch 'main' into DEV-2802
osterman Mar 7, 2025
6a3eff0
Remove unused test, refactor error handling logic
Cerebrovinny Mar 8, 2025
ad772e6
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Mar 8, 2025
5d7148b
Refactor error handling; use global error vars
Cerebrovinny Mar 8, 2025
ed80755
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 8, 2025
7ea21af
Merge branch 'main' into DEV-2802
osterman Mar 10, 2025
717d77a
Merge branch 'main' into DEV-2802
osterman Mar 12, 2025
21167d3
Merge branch 'main' into DEV-2802
osterman Mar 13, 2025
92325c8
Add command alias processing to build hierarchy
Cerebrovinny Mar 14, 2025
f631737
Merge remote-tracking branch 'origin/main' into DEV-2802
Cerebrovinny Mar 14, 2025
63c7942
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 14, 2025
3bd769b
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Mar 14, 2025
557f92c
added cli tests
Cerebrovinny Mar 14, 2025
42dbd63
Add newline before Flags section in test snapshot
Cerebrovinny Mar 14, 2025
93b8197
Add os import, log package; print JSON to stderr
Cerebrovinny Mar 14, 2025
e81fe62
Simplify list command usage string
Cerebrovinny Mar 14, 2025
ab26627
Refactor error logging tests; add helper function
Cerebrovinny Mar 14, 2025
0ae9e94
Update comment punctuation in test helper function
Cerebrovinny Mar 14, 2025
791b154
Refactor settings extraction; add terraform support
Cerebrovinny Mar 14, 2025
ed9a329
Refactor: Use constants for component keys, update tests
Cerebrovinny Mar 14, 2025
d7084e9
Remove unused os import; streamline JSON logging logic
Cerebrovinny Mar 14, 2025
11eff13
Revert "Remove unused os import; streamline JSON logging logic"
Cerebrovinny Mar 14, 2025
c0e163b
back to main code
Cerebrovinny Mar 14, 2025
ce3d23d
Change LogDebug to LogInfo in JSON print function
Cerebrovinny Mar 14, 2025
84c48e8
revert list stacks
Cerebrovinny Mar 14, 2025
f258081
Update listCmd to focus on stacks/components
Cerebrovinny Mar 14, 2025
f66918d
Refactor config check, add testable funcs, rm unused code
Cerebrovinny Mar 15, 2025
4078ac5
Revert "Refactor config check, add testable funcs, rm unused code"
Cerebrovinny Mar 15, 2025
51a762e
clean up old values
Cerebrovinny Mar 15, 2025
c33bae5
stash clean
Cerebrovinny Mar 15, 2025
f3dc378
Add error handling, logging & unit tests for flags
Cerebrovinny Mar 15, 2025
ad4f21e
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 16, 2025
1ff4184
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 17, 2025
d5f4ff8
Switch to YQ for querying, refactor value extraction
Cerebrovinny Mar 17, 2025
3835af0
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Mar 17, 2025
f5ca821
clean up values
Cerebrovinny Mar 17, 2025
3057beb
Add minimal config to avoid nil pointer
Cerebrovinny Mar 17, 2025
8bd822e
Update cmd/list_values_internal_test.go
Cerebrovinny Mar 17, 2025
a4e98b6
Update cmd/list_values.go
Cerebrovinny Mar 17, 2025
788482c
Update cmd/list_values.go
Cerebrovinny Mar 17, 2025
fa33b51
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 17, 2025
6e5fe09
Update pkg/list/flags/flags.go
Cerebrovinny Mar 17, 2025
9a7e43c
Update pkg/list/flags/flags.go
Cerebrovinny Mar 17, 2025
4d0460e
Merge branch 'main' into DEV-2802
osterman Mar 17, 2025
17c0043
Revert "Add minimal config to avoid nil pointer"
Cerebrovinny Mar 17, 2025
5de6834
Add sidebar labels, new docs for vars & workflows
Cerebrovinny Mar 17, 2025
8bf47f5
Fix relative link path in list-workflows doc
Cerebrovinny Mar 17, 2025
87dcd88
Remove related commands sections from docs
Cerebrovinny Mar 17, 2025
3d26aac
Add sidebar label and class name to CLI doc
Cerebrovinny Mar 18, 2025
099002d
Improve error handling, add flags, update tests
Cerebrovinny Mar 18, 2025
132868f
Add flags for template/YAML processing, update logs
Cerebrovinny Mar 18, 2025
40e08c1
Refactor flag handling; centralize processing logic
Cerebrovinny Mar 18, 2025
c33c203
Refactor error handling, add ProcessingOptions struct
Cerebrovinny Mar 18, 2025
d3828ef
Refactor error formatting with const string
Cerebrovinny Mar 18, 2025
4ae107e
Merge branch 'main' into DEV-2802
aknysh Mar 20, 2025
3da1b5e
Merge branch 'main' into DEV-2802
aknysh Mar 21, 2025
b7982e6
add `-s` shorthand for the `--stack` flag
aknysh Mar 23, 2025
b93d445
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 26, 2025
6ad8e65
Add component filtering, error handling improvements
Cerebrovinny Mar 26, 2025
653dc71
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Mar 26, 2025
2e2d424
Refactor error handling; add createComponentError function
Cerebrovinny Mar 26, 2025
d5e4feb
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 26, 2025
dd949ad
Handle nonexistent components; clean up error handling
Cerebrovinny Mar 26, 2025
c696689
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Mar 26, 2025
52bbbcc
fixes for vars
Cerebrovinny Mar 27, 2025
8f5a1bf
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 27, 2025
c89eb31
lint fixes
Cerebrovinny Mar 27, 2025
c714434
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 27, 2025
f554597
Merge branch 'main' into DEV-2802
aknysh Mar 28, 2025
99cc20f
Add component existence check, refactor error handling
Cerebrovinny Mar 28, 2025
aece121
Add error tests, refactor metadata handling
Cerebrovinny Mar 28, 2025
bd7844b
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 28, 2025
dbb4125
Refactor: Move checkComponentExists to utils package
Cerebrovinny Mar 28, 2025
4f0cc66
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Mar 28, 2025
8274bde
Refactor listValues; split logic into helper funcs
Cerebrovinny Mar 28, 2025
36ce3b5
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 28, 2025
f18861d
Refactor IsEmptyTable for conciseness
Cerebrovinny Mar 28, 2025
5b8f77d
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny Mar 28, 2025
a1eee40
Merge branch 'main' into DEV-2802
Cerebrovinny Mar 30, 2025
2e5ce5a
Merge branch 'main' into DEV-2802
aknysh Apr 1, 2025
ba6ea3c
Merge branch 'main' into DEV-2802
aknysh Apr 1, 2025
90d235c
update docs
aknysh Apr 1, 2025
c4f950f
update docs
aknysh Apr 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ linters-settings:
excludes:
- G101 # Look for hard coded credentials

gofmt:
# Simplify code: gofmt -s
simplify: true
# Define indentation
rewrite-rules:
- pattern: "interface{}"
replacement: "any"

cyclop:
# Maximum function complexity
max-complexity: 15
Expand Down Expand Up @@ -206,6 +198,7 @@ issues:
- errcheck
- funlen
- gci
- gocognit
- gosec
- revive

Expand Down
179 changes: 179 additions & 0 deletions cmd/list_errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package cmd

import (
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"

"github.com/cloudposse/atmos/pkg/list/errors"
)

// setupTestCommand creates a test command with the necessary flags.
func setupTestCommand(use string) *cobra.Command {
cmd := &cobra.Command{
Use: use,
}
cmd.PersistentFlags().String("format", "", "Output format")
cmd.PersistentFlags().String("delimiter", "", "Delimiter for CSV/TSV output")
cmd.PersistentFlags().String("stack", "", "Stack pattern")
cmd.PersistentFlags().String("query", "", "JQ query")
cmd.PersistentFlags().Int("max-columns", 0, "Maximum columns")
cmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing")
cmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing")
return cmd
}

// TestComponentDefinitionNotFoundError tests that the ComponentDefinitionNotFoundError.
func TestComponentDefinitionNotFoundError(t *testing.T) {
testCases := []struct {
name string
componentName string
expectedOutput string
runFunc func(cmd *cobra.Command, args []string) (string, error)
}{
{
name: "list values - component not found",
componentName: "nonexistent-component",
expectedOutput: "component 'nonexistent-component' does not exist",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
return "", &errors.ComponentDefinitionNotFoundError{Component: args[0]}
},
},
{
name: "list settings - component not found",
componentName: "nonexistent-component",
expectedOutput: "component 'nonexistent-component' does not exist",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
return "", &errors.ComponentDefinitionNotFoundError{Component: args[0]}
},
},
{
name: "list metadata - component not found",
componentName: "nonexistent-component",
expectedOutput: "component 'nonexistent-component' does not exist",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
return "", &errors.ComponentDefinitionNotFoundError{Component: args[0]}
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Create test command
cmd := setupTestCommand(tc.name)
args := []string{tc.componentName}

// Mock the listValues/listSettings/listMetadata function
mockRunFunc := tc.runFunc

// Run the command with the mocked function
output, err := mockRunFunc(cmd, args)
assert.Equal(t, "", output)
assert.Error(t, err)

// Check that the error is of the expected type
var componentNotFoundErr *errors.ComponentDefinitionNotFoundError
assert.ErrorAs(t, err, &componentNotFoundErr)
assert.Equal(t, tc.componentName, componentNotFoundErr.Component)
assert.Contains(t, componentNotFoundErr.Error(), tc.expectedOutput)

// Verify that the error would be properly returned by the RunE function
// This simulates what would happen in the actual command execution
// where errors are returned to main() instead of being logged
assert.NotNil(t, err, "Error should be returned to be handled by main()")
})
}
}

// TestNoValuesFoundError tests that the NoValuesFoundError is properly handled.
func TestNoValuesFoundError(t *testing.T) {
testCases := []struct {
name string
componentName string
query string
expectedOutput string
runFunc func(cmd *cobra.Command, args []string) (string, error)
shouldReturnNil bool
}{
{
name: "list values - no values found",
componentName: "test-component",
expectedOutput: "No values found for component 'test-component'",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
return "", &errors.NoValuesFoundError{Component: args[0]}
},
shouldReturnNil: false,
},
{
name: "list vars - no vars found",
componentName: "test-component",
query: ".vars",
expectedOutput: "No vars found for component 'test-component'",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
cmd.Flags().Set("query", ".vars")
return "", &errors.NoValuesFoundError{Component: args[0]}
},
shouldReturnNil: true,
},
{
name: "list settings - no settings found with component",
componentName: "test-component",
expectedOutput: "No settings found for component 'test-component'",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
return "", &errors.NoValuesFoundError{Component: args[0]}
},
shouldReturnNil: false,
},
{
name: "list settings - no settings found without component",
componentName: "",
expectedOutput: "No settings found",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
return "", &errors.NoValuesFoundError{}
},
shouldReturnNil: false,
},
{
name: "list metadata - no metadata found with component",
componentName: "test-component",
expectedOutput: "No metadata found for component 'test-component'",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
return "", &errors.NoValuesFoundError{Component: args[0]}
},
shouldReturnNil: false,
},
{
name: "list metadata - no metadata found without component",
componentName: "",
expectedOutput: "No metadata found",
runFunc: func(cmd *cobra.Command, args []string) (string, error) {
return "", &errors.NoValuesFoundError{}
},
shouldReturnNil: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmd := setupTestCommand(tc.name)
args := []string{}
if tc.componentName != "" {
args = append(args, tc.componentName)
}

if tc.query != "" {
cmd.Flags().Set("query", tc.query)
}

mockRunFunc := tc.runFunc

output, err := mockRunFunc(cmd, args)
assert.Equal(t, "", output)
assert.Error(t, err)

var noValuesErr *errors.NoValuesFoundError
assert.ErrorAs(t, err, &noValuesErr)
})
}
}
169 changes: 169 additions & 0 deletions cmd/list_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package cmd

import (
"errors"
"fmt"

listutils "github.com/cloudposse/atmos/pkg/list/utils"

log "github.com/charmbracelet/log"
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/config"
l "github.com/cloudposse/atmos/pkg/list"
listerrors "github.com/cloudposse/atmos/pkg/list/errors"
fl "github.com/cloudposse/atmos/pkg/list/flags"
f "github.com/cloudposse/atmos/pkg/list/format"
u "github.com/cloudposse/atmos/pkg/list/utils"
"github.com/cloudposse/atmos/pkg/schema"
utils "github.com/cloudposse/atmos/pkg/utils"
)

// listMetadataCmd lists metadata across stacks.
var listMetadataCmd = &cobra.Command{
Use: "metadata [component]",
Short: "List metadata across stacks",
Long: "List metadata information across all stacks or for a specific component",
Example: "atmos list metadata\n" +
"atmos list metadata c1\n" +
"atmos list metadata --query .component\n" +
"atmos list metadata --format json\n" +
"atmos list metadata --stack '*-{dev,staging}-*'\n" +
"atmos list metadata --stack 'prod-*'",
RunE: func(cmd *cobra.Command, args []string) error {
checkAtmosConfig()
output, err := listMetadata(cmd, args)
if err != nil {
return err
}

Check warning on line 39 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L34-L39

Added lines #L34 - L39 were not covered by tests

utils.PrintMessage(output)
return nil

Check warning on line 42 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L41-L42

Added lines #L41 - L42 were not covered by tests
},
}

func init() {
fl.AddCommonListFlags(listMetadataCmd)

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

AddStackCompletion(listMetadataCmd)

listCmd.AddCommand(listMetadataCmd)
}

// setupMetadataOptions sets up the filter options for metadata listing.
func setupMetadataOptions(commonFlags fl.CommonFlags, componentFilter string) *l.FilterOptions {
query := commonFlags.Query
if query == "" {
query = ".metadata"
}

Check warning on line 63 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L59-L63

Added lines #L59 - L63 were not covered by tests

return &l.FilterOptions{
Component: l.KeyMetadata,
ComponentFilter: componentFilter,
Query: query,
IncludeAbstract: false,
MaxColumns: commonFlags.MaxColumns,
FormatStr: commonFlags.Format,
Delimiter: commonFlags.Delimiter,
StackPattern: commonFlags.Stack,
}

Check warning on line 74 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L65-L74

Added lines #L65 - L74 were not covered by tests
}

// logNoMetadataFoundMessage logs an appropriate message when no metadata is found.
func logNoMetadataFoundMessage(componentFilter string) {
if componentFilter != "" {
log.Info(fmt.Sprintf("No metadata found for component '%s'", componentFilter))
} else {
log.Info("No metadata found")
}

Check warning on line 83 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L78-L83

Added lines #L78 - L83 were not covered by tests
}

// MetadataParams contains the parameters needed for listing metadata.
type MetadataParams struct {
CommonFlags *fl.CommonFlags
ProcessingFlags *fl.ProcessingFlags
ComponentFilter string
}

// initMetadataParams initializes and returns the parameters needed for listing metadata.
func initMetadataParams(cmd *cobra.Command, args []string) (*MetadataParams, error) {
commonFlags, err := fl.GetCommonListFlags(cmd)
if err != nil {
return nil, &listerrors.QueryError{
Query: "common flags",
Cause: err,
}
}

Check warning on line 101 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L94-L101

Added lines #L94 - L101 were not covered by tests

processingFlags := fl.GetProcessingFlags(cmd)

if f.Format(commonFlags.Format) == f.FormatCSV && commonFlags.Delimiter == f.DefaultTSVDelimiter {
commonFlags.Delimiter = f.DefaultCSVDelimiter
}

Check warning on line 107 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L103-L107

Added lines #L103 - L107 were not covered by tests

componentFilter := ""
if len(args) > 0 {
componentFilter = args[0]
}

Check warning on line 112 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L109-L112

Added lines #L109 - L112 were not covered by tests

return &MetadataParams{
CommonFlags: commonFlags,
ProcessingFlags: processingFlags,
ComponentFilter: componentFilter,
}, nil

Check warning on line 118 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L114-L118

Added lines #L114 - L118 were not covered by tests
}

func listMetadata(cmd *cobra.Command, args []string) (string, error) {
params, err := initMetadataParams(cmd, args)
if err != nil {
return "", err
}

Check warning on line 125 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L121-L125

Added lines #L121 - L125 were not covered by tests

// Initialize CLI config
configAndStacksInfo := schema.ConfigAndStacksInfo{}
atmosConfig, err := config.InitCliConfig(configAndStacksInfo, true)
if err != nil {
return "", &listerrors.InitConfigError{Cause: err}
}

Check warning on line 132 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L128-L132

Added lines #L128 - L132 were not covered by tests

if params.ComponentFilter != "" {
if !listutils.CheckComponentExists(&atmosConfig, params.ComponentFilter) {
return "", &listerrors.ComponentDefinitionNotFoundError{Component: params.ComponentFilter}
}

Check warning on line 137 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L134-L137

Added lines #L134 - L137 were not covered by tests
}

// Get all stacks
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false,
params.ProcessingFlags.Templates, params.ProcessingFlags.Functions, false, nil)
if err != nil {
return "", &listerrors.DescribeStacksError{Cause: err}
}

Check warning on line 145 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L141-L145

Added lines #L141 - L145 were not covered by tests

log.Debug("Filtering metadata",
"component", params.ComponentFilter, "query", params.CommonFlags.Query,
"maxColumns", params.CommonFlags.MaxColumns, "format", params.CommonFlags.Format,
"stackPattern", params.CommonFlags.Stack, "templates", params.ProcessingFlags.Templates)

filterOptions := setupMetadataOptions(*params.CommonFlags, params.ComponentFilter)
output, err := l.FilterAndListValues(stacksMap, filterOptions)
if err != nil {
var noValuesErr *listerrors.NoValuesFoundError
if errors.As(err, &noValuesErr) {
logNoMetadataFoundMessage(params.ComponentFilter)
return "", nil
}
return "", err

Check warning on line 160 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L147-L160

Added lines #L147 - L160 were not covered by tests
}

if output == "" || u.IsEmptyTable(output) {
logNoMetadataFoundMessage(params.ComponentFilter)
return "", nil
}

Check warning on line 166 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L163-L166

Added lines #L163 - L166 were not covered by tests

return output, nil

Check warning on line 168 in cmd/list_metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_metadata.go#L168

Added line #L168 was not covered by tests
}
Loading
Loading