Skip to content

Commit

Permalink
feat: add with-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Jan 30, 2024
1 parent 1827167 commit 454121b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
17 changes: 11 additions & 6 deletions cmd/actions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import (
)

var (
flagBuilds bool
flagCharts bool
flagWithBuilds bool
flagWithCharts bool
flagWithTags bool
)

func init() {
listCmd.Flags().StringSliceVar(&flagTags, "tags", nil, "list of tags to include or exclude (can specify multiple or separate values with commas: tag1,tag2,-tag3)")
listCmd.Flags().BoolVar(&flagCharts, "charts", false, "include charts")
listCmd.Flags().BoolVar(&flagBuilds, "builds", false, "include builds")
listCmd.Flags().BoolVar(&flagWithTags, "with-tags", false, "include tags")
listCmd.Flags().BoolVar(&flagWithCharts, "with-charts", false, "include charts")
listCmd.Flags().BoolVar(&flagWithBuilds, "with-builds", false, "include builds")
}

var listCmd = &cobra.Command{
Expand All @@ -43,10 +45,13 @@ var listCmd = &cobra.Command{
list = append(list, pterm.LeveledListItem{Level: 0, Text: key})
return value.Iterate(func(k string, v *config.Unit) error {
list = append(list, pterm.LeveledListItem{Level: 1, Text: k})
if flagCharts {
if flagWithTags && len(v.Tags) > 0 {
list = append(list, pterm.LeveledListItem{Level: 2, Text: "🔖: " + v.Tags.SortedString()})
}
if flagWithCharts && len(v.Chart.String()) > 0 {
list = append(list, pterm.LeveledListItem{Level: 2, Text: "📑: " + v.Chart.String()})
}
if flagBuilds {
if flagWithBuilds && len(v.Builds) > 0 {
for name, build := range v.Builds {
list = append(list, pterm.LeveledListItem{Level: 2, Text: "📦: " + name})
for _, dependency := range build.Dependencies {
Expand Down
4 changes: 4 additions & 0 deletions internal/config/tag.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package config

type Tag string

func (t Tag) String() string {
return string(t)
}
30 changes: 30 additions & 0 deletions internal/config/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package config

import (
"slices"
"strings"
)

type Tags []Tag

func (t Tags) String() string {
return strings.Join(t.Strings(), ",")
}

func (t Tags) SortedString() string {
return strings.Join(t.SortedStrings(), ",")
}

func (t Tags) Strings() []string {
ret := make([]string, len(t))
for i, tag := range t {
ret[i] = tag.String()
}
return ret
}

func (t Tags) SortedStrings() []string {
ret := t.Strings()
slices.Sort(ret)
return ret
}
2 changes: 1 addition & 1 deletion internal/config/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
type Unit struct {
Chart helm.Dependency `yaml:"chart,omitempty"`
Kustomize string `yaml:"kustomize,omitempty"`
Tags []Tag `yaml:"tags,omitempty"`
Tags Tags `yaml:"tags,omitempty"`
Builds map[string]Build `yaml:"builds,omitempty"`
Values map[string]interface{} `yaml:"values,omitempty"`
}
Expand Down

0 comments on commit 454121b

Please sign in to comment.