-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create
atmos list
command for listing stacks and components (#…
…797) * feat: add atmos list stacks and components command * feat: list commands, update docs * feat: create listing helper functions * feat: create listing helper functions * feat: add spacing * refactor: remove duplicate code, enhance error handling, and update inline docs * feat: add tests * Update pkg/list/list_stacks_test.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update pkg/list/list_components_test.go tests Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: remove list custom command remove custom list command * feat: update tests update tests to include more assertions --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4b30800
commit 3f1cad7
Showing
25 changed files
with
789 additions
and
379 deletions.
There are no files selected for viewing
This file contains 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 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,17 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// listCmd commands list stacks and components | ||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "Execute 'list' commands", | ||
Long: `This command lists stacks and components`, | ||
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(listCmd) | ||
} |
This file contains 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,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
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" | ||
u "github.com/cloudposse/atmos/pkg/utils" | ||
"github.com/fatih/color" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// listComponentsCmd lists atmos components | ||
var listComponentsCmd = &cobra.Command{ | ||
Use: "components", | ||
Short: "Execute 'list components' command", | ||
Long: `This command lists all Atmos components or filters components by stacks.`, | ||
Example: "atmos list components\n" + | ||
"atmos list components -s <stack>", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Check Atmos configuration | ||
checkAtmosConfig() | ||
|
||
stackFlag, _ := cmd.Flags().GetString("stack") | ||
|
||
configAndStacksInfo := schema.ConfigAndStacksInfo{} | ||
cliConfig, err := config.InitCliConfig(configAndStacksInfo, true) | ||
if err != nil { | ||
u.PrintMessageInColor(fmt.Sprintf("Error initializing CLI config: %v", err), color.New(color.FgRed)) | ||
return | ||
} | ||
|
||
stacksMap, err := e.ExecuteDescribeStacks(cliConfig, "", nil, nil, nil, false, false, false) | ||
if err != nil { | ||
u.PrintMessageInColor(fmt.Sprintf("Error describing stacks: %v", err), color.New(color.FgRed)) | ||
return | ||
} | ||
|
||
output, err := l.FilterAndListComponents(stackFlag, stacksMap) | ||
if err != nil { | ||
u.PrintMessageInColor(fmt.Sprintf("Error: %v"+"\n", err), color.New(color.FgYellow)) | ||
return | ||
} | ||
|
||
u.PrintMessageInColor(output, color.New(color.FgGreen)) | ||
}, | ||
} | ||
|
||
func init() { | ||
listComponentsCmd.PersistentFlags().StringP("stack", "s", "", "Filter components by stack (e.g., atmos list components -s stack1)") | ||
listCmd.AddCommand(listComponentsCmd) | ||
} |
This file contains 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,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
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" | ||
u "github.com/cloudposse/atmos/pkg/utils" | ||
"github.com/fatih/color" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// listStacksCmd lists atmos stacks | ||
var listStacksCmd = &cobra.Command{ | ||
Use: "stacks", | ||
Short: "Execute 'list stacks' command", | ||
Long: `This command lists all Atmos stacks or all stacks for the specified component: atmos list stacks -c <component>`, | ||
Example: "atmos list stacks\n" + | ||
"atmos list stacks -c <component>", | ||
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Check Atmos configuration | ||
checkAtmosConfig() | ||
|
||
componentFlag, _ := cmd.Flags().GetString("component") | ||
|
||
configAndStacksInfo := schema.ConfigAndStacksInfo{} | ||
cliConfig, err := config.InitCliConfig(configAndStacksInfo, true) | ||
if err != nil { | ||
u.PrintMessageInColor(fmt.Sprintf("Error initializing CLI config: %v", err), color.New(color.FgRed)) | ||
return | ||
} | ||
|
||
stacksMap, err := e.ExecuteDescribeStacks(cliConfig, "", nil, nil, nil, false, false, false) | ||
if err != nil { | ||
u.PrintMessageInColor(fmt.Sprintf("Error describing stacks: %v", err), color.New(color.FgRed)) | ||
return | ||
} | ||
|
||
output, err := l.FilterAndListStacks(stacksMap, componentFlag) | ||
if err != nil { | ||
u.PrintMessageInColor(fmt.Sprintf("Error filtering stacks: %v", err), color.New(color.FgRed)) | ||
return | ||
} | ||
u.PrintMessageInColor(output, color.New(color.FgGreen)) | ||
}, | ||
} | ||
|
||
func init() { | ||
listStacksCmd.DisableFlagParsing = false | ||
listStacksCmd.PersistentFlags().StringP("component", "c", "", "atmos list stacks -c <component>") | ||
listCmd.AddCommand(listStacksCmd) | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.