Skip to content

Commit

Permalink
feat: Enable sorting images by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Jul 3, 2023
1 parent be914d5 commit e935e05
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func registerFlags(cmd *cobra.Command, images *pkg.Images) {
"regex used to split helm template rendered")
cmd.Flags().BoolVarP(&images.UniqueImages, "unique", "u", true,
"enable the flag if duplicates to be removed from the retrieved list")
cmd.Flags().BoolVarP(&images.SortImages, "sort", "s", true,
"enable the flag to sort images")
cmd.Flags().BoolVarP(&images.JSON, "json", "j", false,
"enable the flag to display images retrieved in json format (disabled by default)")
cmd.Flags().BoolVarP(&images.YAML, "yaml", "y", false,
Expand Down
1 change: 1 addition & 0 deletions docs/doc/list-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ list-images CHART|RELEASE [flags]
--set-json stringArray set JSON values on the command line (can specify multiple or separate values with commas: key1=jsonval1,key2=jsonval2)
--set-literal stringArray set a literal STRING value on the command line
--set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
-s, --sort enable the flag to sort images (default true)
-t, --table enable the flag to display images retrieved in table format (disabled by default)
-u, --unique enable the flag if duplicates to be removed from the retrieved list (default true)
-f, --values ValueFiles specify values in a YAML file (can specify multiple) (default [])
Expand Down
1 change: 1 addition & 0 deletions pkg/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Images struct {
LogLevel string
FromRelease bool
UniqueImages bool
SortImages bool
IncludeTestImages bool
KubeVersion string
ChartVersionConstraint string
Expand Down
5 changes: 5 additions & 0 deletions pkg/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"sort"
"strings"

"github.com/cheynewallace/tabby"
Expand Down Expand Up @@ -40,6 +41,10 @@ func (image *Images) render(images []*k8s.Image) error {
imags = GetUniqEntries(imags)
}

if image.SortImages {
sort.Stable(sort.StringSlice(imags))
}

if _, err := fmt.Fprintf(image.writer, "%s\n", strings.Join(imags, "\n")); err != nil {
image.log.Fatalln(err)
}
Expand Down

0 comments on commit e935e05

Please sign in to comment.