Skip to content
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

Implement: atmos list values #1036

Open
wants to merge 74 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 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
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
12 changes: 2 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ linters:
- gocognit # Check cognitive complexity
- gocritic # Enable additional checks for code issues
- godot # Enforce comment formatting
- gofmt # Enforce gofmt style
- gofumpt # Enforce consistent formatting
- goimports # Enforce import formatting
- gosec # Inspect source code for security problems
Expand Down Expand Up @@ -51,14 +50,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"

Comment on lines -54 to -61
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was 👍 from me. Since we're using gofumpt for auto-formatting (see autofix workflow), the gofmt is at odds with it.

cyclop:
# Maximum function complexity
max-complexity: 15
Expand Down Expand Up @@ -104,7 +95,7 @@ linters-settings:
- name: add-constant
arguments:
- maxLitCount: "3"
allowStrs: '""'
allowStrs: '"","error"'
allowInts: "0,1,2,3,4"
allowFloats: "0.0,0.,1.0,1.,2.0,2."
- name: argument-limit
Expand Down Expand Up @@ -169,6 +160,7 @@ issues:
- funlen
- revive
- gci
- gocognit

output:
formats:
Expand Down
6 changes: 0 additions & 6 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ func processCustomCommands(
var command *cobra.Command
existingTopLevelCommands := make(map[string]*cobra.Command)

// Build commands and their hierarchy from the alias map
for alias, fullCmd := range atmosConfig.CommandAliases {
parts := strings.Fields(fullCmd)
addCommandWithAlias(RootCmd, alias, parts)
}

if topLevel {
existingTopLevelCommands = getTopLevelCommands()
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"github.com/spf13/cobra"
)

// listCmd commands list stacks and components
// listCmd represents the base list command that provides subcommands for listing
// various Atmos resources like stacks, components, settings, metadata, etc.
var listCmd = &cobra.Command{
Use: "list",
Short: "List available stacks and components",
Long: `Display a list of all available stacks and components defined in your project.`,
Use: "list [command]",
Short: "List Atmos resources and configurations",
Long: "List and display Atmos resources and configurations",
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Args: cobra.NoArgs,
}
Expand Down
97 changes: 97 additions & 0 deletions cmd/list_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package cmd

import (
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"
"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",
Short: "List metadata across stacks",
Long: "List metadata information across all stacks",
Example: "atmos list metadata\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-*'",
Run: func(cmd *cobra.Command, args []string) {
// Check Atmos configuration
checkAtmosConfig()
output, err := listMetadata(cmd)
if err != nil {
log.Error("failed to list metadata", "error", err)
return
}

utils.PrintMessage(output)
},
}

func init() {
fl.AddCommonListFlags(listMetadataCmd)

AddStackCompletion(listMetadataCmd)

listCmd.AddCommand(listMetadataCmd)
}

func listMetadata(cmd *cobra.Command) (string, error) {
commonFlags, err := fl.GetCommonListFlags(cmd)
if err != nil {
return "", &errors.QueryError{
Query: "common flags",
Cause: err,
}
}

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

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

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

// Use .metadata as the default query if none provided
if commonFlags.Query == "" {
commonFlags.Query = ".metadata"
}

output, err := l.FilterAndListValues(stacksMap, &l.FilterOptions{
Component: "",
Query: commonFlags.Query,
IncludeAbstract: false,
MaxColumns: commonFlags.MaxColumns,
FormatStr: commonFlags.Format,
Delimiter: commonFlags.Delimiter,
StackPattern: commonFlags.Stack,
})
if err != nil {
if u.IsNoValuesFoundError(err) {
return "", &errors.NoMetadataFoundError{Query: commonFlags.Query}
}
return "", &errors.MetadataFilteringError{Cause: err}
}

return output, nil
}
91 changes: 91 additions & 0 deletions cmd/list_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package cmd

import (
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"
"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"
)

// listSettingsCmd lists settings across stacks.
var listSettingsCmd = &cobra.Command{
Use: "settings",
Short: "List settings across stacks",
Long: "List settings configuration across all stacks",
Example: "atmos list settings\n" +
"atmos list settings --query .terraform\n" +
"atmos list settings --format json\n" +
"atmos list settings --stack '*-dev-*'\n" +
"atmos list settings --stack 'prod-*'",
Run: func(cmd *cobra.Command, args []string) {
// Check Atmos configuration
checkAtmosConfig()
output, err := listSettings(cmd)
if err != nil {
log.Error("failed to list settings", "error", err)
return
}

utils.PrintMessage(output)
},
}

func init() {
fl.AddCommonListFlags(listSettingsCmd)

AddStackCompletion(listSettingsCmd)

listCmd.AddCommand(listSettingsCmd)
}

func listSettings(cmd *cobra.Command) (string, error) {
// Get common flags
commonFlags, err := fl.GetCommonListFlags(cmd)
if err != nil {
return "", &errors.CommonFlagsError{Cause: err}
}

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

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

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

// Use empty query to avoid further processing since handleComponentProperties will extract the settings
output, err := l.FilterAndListValues(stacksMap, &l.FilterOptions{
Component: "settings",
Query: commonFlags.Query,
IncludeAbstract: false,
MaxColumns: commonFlags.MaxColumns,
FormatStr: commonFlags.Format,
Delimiter: commonFlags.Delimiter,
StackPattern: commonFlags.Stack,
})
if err != nil {
if u.IsNoValuesFoundError(err) {
return "", &errors.NoSettingsFoundError{Query: commonFlags.Query}
}
return "", &errors.SettingsFilteringError{Cause: err}
}

return output, nil
}
15 changes: 8 additions & 7 deletions cmd/list_stacks.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package cmd

import (
"fmt"
"strings"

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"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/cloudposse/atmos/pkg/utils"
)

// listStacksCmd lists atmos stacks
Expand All @@ -28,10 +27,10 @@ var listStacksCmd = &cobra.Command{
checkAtmosConfig()
output, err := listStacks(cmd)
if err != nil {
u.PrintErrorMarkdownAndExit("Error filtering stacks", err, "")
log.Error("error filtering stacks", "error", err)
return
}
u.PrintMessageInColor(strings.Join(output, "\n")+"\n", theme.Colors.Success)
utils.PrintMessage(strings.Join(output, "\n"))
},
}

Expand All @@ -46,11 +45,13 @@ func listStacks(cmd *cobra.Command) ([]string, error) {
configAndStacksInfo := schema.ConfigAndStacksInfo{}
atmosConfig, err := config.InitCliConfig(configAndStacksInfo, true)
if err != nil {
return nil, fmt.Errorf("Error initializing CLI config: %v", err)
log.Error("failed to initialize CLI config", "error", err)
return nil, err
}
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, false, false, false, nil)
if err != nil {
return nil, fmt.Errorf("Error describing stacks: %v", err)
log.Error("failed to describe stacks", "error", err)
return nil, err
}

output, err := l.FilterAndListStacks(stacksMap, componentFlag)
Expand Down
Loading