-
-
Notifications
You must be signed in to change notification settings - Fork 140
Implement: atmos list values #1036
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
Merged
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 547f984
feat: add TSV format support for workflow listing
Cerebrovinny 917cdd0
wip
Cerebrovinny 72a8e76
[autofix.ci] apply automated fixes
autofix-ci[bot] b6b19b2
Merge branch 'main' into DEV-2802
Cerebrovinny 30e14d0
update list values
Cerebrovinny f3db126
[autofix.ci] apply automated fixes
autofix-ci[bot] 54d8ad0
fixes and clean up
Cerebrovinny b03b3c2
[autofix.ci] apply automated fixes
autofix-ci[bot] cc9c8bf
update terminal
Cerebrovinny 9060a00
test list values
Cerebrovinny 79e94f8
Update website/docs/cli/commands/list/list-values.mdx
Cerebrovinny cfec6fb
Add markdown docs for listing values/vars; update examples
Cerebrovinny df4c494
Add logger, replace error prints with log calls
Cerebrovinny 872d881
Refactor imports and rename logger variable
Cerebrovinny 368d21d
Handle 'no values found' error; improve logging logic
Cerebrovinny 6a3e02b
Improve error messages with colored output
Cerebrovinny 538d6b7
Add expectedError field to test cases for error validation
Cerebrovinny 216e6cd
Merge branch 'main' into DEV-2802
Cerebrovinny 6d87e2c
Refactor error handling, add custom error type
Cerebrovinny befa005
Refactor error handling, update TTY check logic
Cerebrovinny f07cb4a
Refactor commands to list metadata and settings
Cerebrovinny 132dfce
general fixes
Cerebrovinny 52f11fb
Remove unused getMapKeys function
Cerebrovinny ab3bde4
[autofix.ci] apply automated fixes
autofix-ci[bot] 948a3c0
Merge branch 'main' into DEV-2802
Cerebrovinny 1ce3cf4
Merge branch 'main' into DEV-2802
Cerebrovinny 571d382
Merge branch 'main' into DEV-2802
Cerebrovinny 9b72518
Switch to charmbracelet/log, remove custom logger setup
Cerebrovinny f4779cc
[autofix.ci] apply automated fixes
autofix-ci[bot] 7d92050
Remove examples from command help, update markdown docs
Cerebrovinny 4e758fc
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny a2f790c
Merge branch 'main' into DEV-2802
Cerebrovinny d0e24c3
[autofix.ci] apply automated fixes
autofix-ci[bot] 53f83ab
Refactor error logging, simplify path conversion
Cerebrovinny e0ec172
Merge branch 'main' into DEV-2802
Cerebrovinny a8af871
Merge branch 'main' into DEV-2802
osterman de1e0e2
Refactor imports, improve error logging
Cerebrovinny 5fbaeef
Refactor list commands, add common flags & error handling
Cerebrovinny cc864f6
clean up
Cerebrovinny 936bb93
Update website/docs/cli/commands/list/list-metadata.mdx
Cerebrovinny 74842b7
Improve list commands & table formatting
Cerebrovinny 9017862
[autofix.ci] apply automated fixes
autofix-ci[bot] e45f2ff
Update website/docs/cli/commands/list/list-settings.mdx
Cerebrovinny e3d0c38
Update query docs and linter configuration
Cerebrovinny 1de71b5
Improve table and delimited formatter
Cerebrovinny 9be83fa
refactor and clean up
Cerebrovinny cf17568
lint static fixes
Cerebrovinny 735f339
[autofix.ci] apply automated fixes
autofix-ci[bot] ae180a2
fixes lint static check
Cerebrovinny 67b8ce4
[autofix.ci] apply automated fixes
autofix-ci[bot] 47ecda6
fixes lint static check
Cerebrovinny 404f398
lint fixes
Cerebrovinny feeecdd
clean up the processcustomcommands is already on process command aliases
Cerebrovinny 153a751
chore: update tests
Cerebrovinny 4fa3270
disable vendor pull tests
Cerebrovinny 7773a61
fix: unix line break windows
Cerebrovinny 725825e
Update website/docs/cli/commands/list/list-metadata.mdx
Cerebrovinny 38c14d3
Update website/docs/cli/commands/list/list-settings.mdx
Cerebrovinny a4ab6ea
Update cmd/markdown/atmos_list_vars_usage.md
Cerebrovinny 4a69ea0
Update cmd/markdown/atmos_list_values_usage.md
Cerebrovinny 7d0c33d
Update cmd/list_metadata.go
Cerebrovinny 86aef46
Update website/docs/cli/commands/list/list-settings.mdx
Cerebrovinny 2814f90
Update website/docs/cli/commands/list/list-settings.mdx
Cerebrovinny a042ce4
Update website/docs/cli/commands/list/list-metadata.mdx
Cerebrovinny fbec33d
fix: tests improvements
Cerebrovinny 9eb34d2
fix: delimited
Cerebrovinny 487bfef
[autofix.ci] apply automated fixes
autofix-ci[bot] 0cf853b
disable vendor
Cerebrovinny d490867
Update pkg/utils/wildcard.go
Cerebrovinny 89accc3
fix: fixes build
Cerebrovinny e781fb5
disable vendor
Cerebrovinny 31e9b74
fix: disable more oci tests
Cerebrovinny 19b252b
fix: disable more oci tests
Cerebrovinny 51681d4
Merge branch 'main' into DEV-2802
osterman 9c17849
Merge branch 'main' into DEV-2802
osterman 90333d4
Merge branch 'main' into DEV-2802
osterman 42e2d7b
Merge branch 'main' into DEV-2802
osterman ab7dcd5
fixes and increase extract coverage
Cerebrovinny bd8e4e8
Merge branch 'main' into DEV-2802
osterman 1345a7b
Add tests for common list flags handling
Cerebrovinny 5517e7b
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny 078575d
Refactor funcs, add tests for error handling
Cerebrovinny e63ea78
Merge branch 'main' into DEV-2802
osterman 991a0af
[autofix.ci] apply automated fixes
autofix-ci[bot] c12fd07
Add internal tests for list metadata command
Cerebrovinny 4f56434
[autofix.ci] apply automated fixes
autofix-ci[bot] e3b9b6e
Add tests for list values and vars command flags
Cerebrovinny 8bcf2fc
added test for json formatter error coverage
Cerebrovinny a03494f
Merge branch 'main' into DEV-2802
Cerebrovinny c12ae08
Add error checks for io.Copy in tests
Cerebrovinny f1c3490
Refactor error handling in test functions
Cerebrovinny d142019
Add periods to comments for consistency.
Cerebrovinny 55a4f82
Add tests for error handling and CSV delimiter logic
Cerebrovinny feb94ff
Merge branch 'main' into DEV-2802
Cerebrovinny 6782e49
Refactor error handling, use static errors for tests
Cerebrovinny f632d6e
[autofix.ci] apply automated fixes
autofix-ci[bot] 62de78b
Merge branch 'main' into DEV-2802
Cerebrovinny 99dc4dd
Merge branch 'main' into DEV-2802
osterman 1bbf67c
Merge branch 'main' into DEV-2802
osterman 6a3eff0
Remove unused test, refactor error handling logic
Cerebrovinny ad772e6
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny 5d7148b
Refactor error handling; use global error vars
Cerebrovinny ed80755
[autofix.ci] apply automated fixes
autofix-ci[bot] 7ea21af
Merge branch 'main' into DEV-2802
osterman 717d77a
Merge branch 'main' into DEV-2802
osterman 21167d3
Merge branch 'main' into DEV-2802
osterman 92325c8
Add command alias processing to build hierarchy
Cerebrovinny f631737
Merge remote-tracking branch 'origin/main' into DEV-2802
Cerebrovinny 63c7942
Merge branch 'main' into DEV-2802
Cerebrovinny 3bd769b
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny 557f92c
added cli tests
Cerebrovinny 42dbd63
Add newline before Flags section in test snapshot
Cerebrovinny 93b8197
Add os import, log package; print JSON to stderr
Cerebrovinny e81fe62
Simplify list command usage string
Cerebrovinny ab26627
Refactor error logging tests; add helper function
Cerebrovinny 0ae9e94
Update comment punctuation in test helper function
Cerebrovinny 791b154
Refactor settings extraction; add terraform support
Cerebrovinny ed9a329
Refactor: Use constants for component keys, update tests
Cerebrovinny d7084e9
Remove unused os import; streamline JSON logging logic
Cerebrovinny 11eff13
Revert "Remove unused os import; streamline JSON logging logic"
Cerebrovinny c0e163b
back to main code
Cerebrovinny ce3d23d
Change LogDebug to LogInfo in JSON print function
Cerebrovinny 84c48e8
revert list stacks
Cerebrovinny f258081
Update listCmd to focus on stacks/components
Cerebrovinny f66918d
Refactor config check, add testable funcs, rm unused code
Cerebrovinny 4078ac5
Revert "Refactor config check, add testable funcs, rm unused code"
Cerebrovinny 51a762e
clean up old values
Cerebrovinny c33bae5
stash clean
Cerebrovinny f3dc378
Add error handling, logging & unit tests for flags
Cerebrovinny ad4f21e
Merge branch 'main' into DEV-2802
Cerebrovinny 1ff4184
Merge branch 'main' into DEV-2802
Cerebrovinny d5f4ff8
Switch to YQ for querying, refactor value extraction
Cerebrovinny 3835af0
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny f5ca821
clean up values
Cerebrovinny 3057beb
Add minimal config to avoid nil pointer
Cerebrovinny 8bd822e
Update cmd/list_values_internal_test.go
Cerebrovinny a4e98b6
Update cmd/list_values.go
Cerebrovinny 788482c
Update cmd/list_values.go
Cerebrovinny fa33b51
Merge branch 'main' into DEV-2802
Cerebrovinny 6e5fe09
Update pkg/list/flags/flags.go
Cerebrovinny 9a7e43c
Update pkg/list/flags/flags.go
Cerebrovinny 4d0460e
Merge branch 'main' into DEV-2802
osterman 17c0043
Revert "Add minimal config to avoid nil pointer"
Cerebrovinny 5de6834
Add sidebar labels, new docs for vars & workflows
Cerebrovinny 8bf47f5
Fix relative link path in list-workflows doc
Cerebrovinny 87dcd88
Remove related commands sections from docs
Cerebrovinny 3d26aac
Add sidebar label and class name to CLI doc
Cerebrovinny 099002d
Improve error handling, add flags, update tests
Cerebrovinny 132868f
Add flags for template/YAML processing, update logs
Cerebrovinny 40e08c1
Refactor flag handling; centralize processing logic
Cerebrovinny c33c203
Refactor error handling, add ProcessingOptions struct
Cerebrovinny d3828ef
Refactor error formatting with const string
Cerebrovinny 4ae107e
Merge branch 'main' into DEV-2802
aknysh 3da1b5e
Merge branch 'main' into DEV-2802
aknysh b7982e6
add `-s` shorthand for the `--stack` flag
aknysh b93d445
Merge branch 'main' into DEV-2802
Cerebrovinny 6ad8e65
Add component filtering, error handling improvements
Cerebrovinny 653dc71
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny 2e2d424
Refactor error handling; add createComponentError function
Cerebrovinny d5e4feb
[autofix.ci] apply automated fixes
autofix-ci[bot] dd949ad
Handle nonexistent components; clean up error handling
Cerebrovinny c696689
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny 52bbbcc
fixes for vars
Cerebrovinny 8f5a1bf
[autofix.ci] apply automated fixes
autofix-ci[bot] c89eb31
lint fixes
Cerebrovinny c714434
Merge branch 'main' into DEV-2802
Cerebrovinny f554597
Merge branch 'main' into DEV-2802
aknysh 99cc20f
Add component existence check, refactor error handling
Cerebrovinny aece121
Add error tests, refactor metadata handling
Cerebrovinny bd7844b
[autofix.ci] apply automated fixes
autofix-ci[bot] dbb4125
Refactor: Move checkComponentExists to utils package
Cerebrovinny 4f0cc66
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny 8274bde
Refactor listValues; split logic into helper funcs
Cerebrovinny 36ce3b5
[autofix.ci] apply automated fixes
autofix-ci[bot] f18861d
Refactor IsEmptyTable for conciseness
Cerebrovinny 5b8f77d
Merge remote-tracking branch 'origin/DEV-2802' into DEV-2802
Cerebrovinny a1eee40
Merge branch 'main' into DEV-2802
Cerebrovinny 2e5ce5a
Merge branch 'main' into DEV-2802
aknysh ba6ea3c
Merge branch 'main' into DEV-2802
aknysh 90d235c
update docs
aknysh c4f950f
update docs
aknysh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
|
|
||
| utils.PrintMessage(output) | ||
| return nil | ||
| }, | ||
Cerebrovinny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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" | ||
| } | ||
|
|
||
| return &l.FilterOptions{ | ||
| Component: l.KeyMetadata, | ||
| ComponentFilter: componentFilter, | ||
| Query: query, | ||
| IncludeAbstract: false, | ||
| MaxColumns: commonFlags.MaxColumns, | ||
| FormatStr: commonFlags.Format, | ||
| Delimiter: commonFlags.Delimiter, | ||
| StackPattern: commonFlags.Stack, | ||
| } | ||
| } | ||
|
|
||
| // 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") | ||
| } | ||
| } | ||
|
|
||
| // 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, | ||
| } | ||
| } | ||
|
|
||
| processingFlags := fl.GetProcessingFlags(cmd) | ||
|
|
||
| if f.Format(commonFlags.Format) == f.FormatCSV && commonFlags.Delimiter == f.DefaultTSVDelimiter { | ||
| commonFlags.Delimiter = f.DefaultCSVDelimiter | ||
| } | ||
|
|
||
| componentFilter := "" | ||
| if len(args) > 0 { | ||
| componentFilter = args[0] | ||
| } | ||
|
|
||
| return &MetadataParams{ | ||
| CommonFlags: commonFlags, | ||
| ProcessingFlags: processingFlags, | ||
| ComponentFilter: componentFilter, | ||
| }, nil | ||
| } | ||
|
|
||
| func listMetadata(cmd *cobra.Command, args []string) (string, error) { | ||
| params, err := initMetadataParams(cmd, args) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| // Initialize CLI config | ||
| configAndStacksInfo := schema.ConfigAndStacksInfo{} | ||
| atmosConfig, err := config.InitCliConfig(configAndStacksInfo, true) | ||
| if err != nil { | ||
| return "", &listerrors.InitConfigError{Cause: err} | ||
| } | ||
|
|
||
| if params.ComponentFilter != "" { | ||
| if !listutils.CheckComponentExists(&atmosConfig, params.ComponentFilter) { | ||
| return "", &listerrors.ComponentDefinitionNotFoundError{Component: params.ComponentFilter} | ||
| } | ||
| } | ||
|
|
||
| // 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} | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
| if output == "" || u.IsEmptyTable(output) { | ||
| logNoMetadataFoundMessage(params.ComponentFilter) | ||
| return "", nil | ||
| } | ||
|
|
||
| return output, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.