Skip to content

atmos list vendor #1192

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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fe7e19c
Adds `list vendor` command
Cerebrovinny Apr 5, 2025
4ef76e2
general refactor em clean code
Cerebrovinny Apr 5, 2025
a8abb9b
general clean up refactor
Cerebrovinny Apr 7, 2025
395d9ac
Merge branch 'main' into feat/list-vendor
Cerebrovinny Apr 7, 2025
5b576e4
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 7, 2025
1779567
update margin const
Cerebrovinny Apr 8, 2025
2451886
Merge remote-tracking branch 'origin/feat/list-vendor' into feat/list…
Cerebrovinny Apr 8, 2025
91935e1
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 8, 2025
ea0c070
refactor expected error
Cerebrovinny Apr 9, 2025
6d21137
clean code
Cerebrovinny Apr 9, 2025
e38e565
clean up refactor
Cerebrovinny Apr 9, 2025
d8fd768
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 9, 2025
6329ba8
Refactors vendor output formatting
Cerebrovinny Apr 9, 2025
5490941
Merge remote-tracking branch 'origin/feat/list-vendor' into feat/list…
Cerebrovinny Apr 9, 2025
f7191cf
clean up
Cerebrovinny Apr 9, 2025
30119a1
Add vendor list config options for format and columns
Cerebrovinny Apr 9, 2025
a23a11f
Merge branch 'main' into feat/list-vendor
Cerebrovinny Apr 11, 2025
dff71bc
Update file parsing to use filetype.DetectFormatAndParseFile
Cerebrovinny Apr 13, 2025
6627fb9
clean up
Cerebrovinny Apr 14, 2025
31b5fda
refactor list vendor
Cerebrovinny Apr 15, 2025
c6e12db
csv tsv format
Cerebrovinny Apr 15, 2025
2df9517
clean up
Cerebrovinny Apr 15, 2025
414bbfc
clean up
Cerebrovinny Apr 15, 2025
9bc44e6
clean up
Cerebrovinny Apr 15, 2025
9604532
Merge branch 'main' into feat/list-vendor
Cerebrovinny Apr 15, 2025
a2f4b11
unit tests for vendor data process
Cerebrovinny Apr 18, 2025
858828a
Merge branch 'main' into feat/list-vendor
Cerebrovinny Apr 20, 2025
ab3f1fb
Merge branch 'main' into feat/list-vendor
Cerebrovinny Apr 30, 2025
6dd4ec6
Merge branch 'main' into feat/list-vendor
Cerebrovinny May 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
87 changes: 87 additions & 0 deletions cmd/list_vendor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package cmd

import (
"fmt"

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

"github.com/cloudposse/atmos/pkg/config"
l "github.com/cloudposse/atmos/pkg/list"
"github.com/cloudposse/atmos/pkg/schema"
)

// listVendorCmd lists vendor configurations.
var listVendorCmd = &cobra.Command{
Use: "vendor",
Short: "List all vendor configurations",
Long: "List all vendor configurations in a tabular way, including component and vendor manifests.",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
// Check Atmos configuration
checkAtmosConfig()

// Get flags
flags := cmd.Flags()

formatFlag, err := flags.GetString("format")
if err != nil {
log.Error("Error getting the 'format' flag", "error", err)
cmd.PrintErrln(fmt.Errorf("error getting the 'format' flag: %w", err))
cmd.PrintErrln("Run 'atmos list vendor --help' for usage")
return
}

Check warning on line 33 in cmd/list_vendor.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_vendor.go#L20-L33

Added lines #L20 - L33 were not covered by tests

stackFlag, err := flags.GetString("stack")
if err != nil {
log.Error("Error getting the 'stack' flag", "error", err)
cmd.PrintErrln(fmt.Errorf("error getting the 'stack' flag: %w", err))
cmd.PrintErrln("Run 'atmos list vendor --help' for usage")
return
}

Check warning on line 41 in cmd/list_vendor.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_vendor.go#L35-L41

Added lines #L35 - L41 were not covered by tests

delimiterFlag, err := flags.GetString("delimiter")
if err != nil {
log.Error("Error getting the 'delimiter' flag", "error", err)
cmd.PrintErrln(fmt.Errorf("error getting the 'delimiter' flag: %w", err))
cmd.PrintErrln("Run 'atmos list vendor --help' for usage")
return
}

Check warning on line 49 in cmd/list_vendor.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_vendor.go#L43-L49

Added lines #L43 - L49 were not covered by tests

// Initialize CLI config
configAndStacksInfo := schema.ConfigAndStacksInfo{}
atmosConfig, err := config.InitCliConfig(configAndStacksInfo, true)
if err != nil {
log.Error("Error initializing CLI config", "error", err)
cmd.PrintErrln(fmt.Errorf("error initializing CLI config: %w", err))
return
}

Check warning on line 58 in cmd/list_vendor.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_vendor.go#L52-L58

Added lines #L52 - L58 were not covered by tests

// Set options
options := &l.FilterOptions{
FormatStr: formatFlag,
StackPattern: stackFlag,
Delimiter: delimiterFlag,
}

// Call list vendor function
output, err := l.FilterAndListVendor(&atmosConfig, options)
if err != nil {
log.Error("Error listing vendor configurations", "error", err)
cmd.PrintErrln(fmt.Errorf("error listing vendor configurations: %w", err))
return
}

Check warning on line 73 in cmd/list_vendor.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_vendor.go#L61-L73

Added lines #L61 - L73 were not covered by tests

// Print output
fmt.Println(output)

Check warning on line 76 in cmd/list_vendor.go

View check run for this annotation

Codecov / codecov/patch

cmd/list_vendor.go#L76

Added line #L76 was not covered by tests
},
}

func init() {
AddStackCompletion(listVendorCmd)
listCmd.AddCommand(listVendorCmd)

// Add flags
listVendorCmd.Flags().StringP("format", "f", "", "Output format: table, json, yaml, csv, tsv")
listVendorCmd.Flags().StringP("delimiter", "d", "", "Delimiter for CSV/TSV output")
}
29 changes: 29 additions & 0 deletions cmd/markdown/atmos_list_vendor_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
– List all vendor configurations
```
$ atmos list vendor
```

– List vendor configurations with a specific output format
```
$ atmos list vendor --format json
```

– List vendor configurations filtered by component name pattern
```
$ atmos list vendor --stack "vpc*"
```

– List vendor configurations with comma-separated CSV format
```
$ atmos list vendor --format csv
```

– List vendor configurations with tab-separated TSV format
```
$ atmos list vendor --format tsv
```

– List vendor configurations with a custom delimiter
```
$ atmos list vendor --format csv --delimiter "|"
```
20 changes: 11 additions & 9 deletions pkg/list/format/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ import (
type Format string

const (
FormatTable Format = "table"
FormatJSON Format = "json"
FormatYAML Format = "yaml"
FormatCSV Format = "csv"
FormatTSV Format = "tsv"
FormatTable Format = "table"
FormatJSON Format = "json"
FormatYAML Format = "yaml"
FormatCSV Format = "csv"
FormatTSV Format = "tsv"
FormatTemplate Format = "template"
)

// FormatOptions contains options for formatting output.
type FormatOptions struct {
MaxColumns int
Delimiter string
TTY bool
Format Format
MaxColumns int
Delimiter string
TTY bool
Format Format
CustomHeaders []string
}

// Formatter defines the interface for formatting output.
Expand Down
14 changes: 10 additions & 4 deletions pkg/list/format/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@
}

// createHeader creates the table header.
func createHeader(stackKeys []string) []string {
func createHeader(stackKeys []string, customHeaders []string) []string {
// If custom headers are provided, use them
if len(customHeaders) > 0 {
return customHeaders
}

Check warning on line 77 in pkg/list/format/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/list/format/table.go#L76-L77

Added lines #L76 - L77 were not covered by tests

// Otherwise, use the default header format
header := []string{"Key"}
return append(header, stackKeys...)
}
Expand Down Expand Up @@ -164,7 +170,7 @@
}

// createStyledTable creates a styled table with headers and rows.
func createStyledTable(header []string, rows [][]string) string {
func CreateStyledTable(header []string, rows [][]string) string {
t := table.New().
Border(lipgloss.ThickBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color(theme.ColorBorder))).
Expand Down Expand Up @@ -206,10 +212,10 @@
ErrTableTooWide.Error(), estimatedWidth, terminalWidth)
}

header := createHeader(stackKeys)
header := createHeader(stackKeys, options.CustomHeaders)
rows := createRows(data, valueKeys, stackKeys)

return createStyledTable(header, rows), nil
return CreateStyledTable(header, rows), nil
}

// calculateMaxKeyWidth determines the maximum width needed for the key column.
Expand Down
Loading