Skip to content

Commit

Permalink
add flag --show-old to only charts not on the latest version (#111)
Browse files Browse the repository at this point in the history
* add flag --show-old to only charts not on the latest version

* replace Fatal with Exitf

Co-authored-by: Andrew Suderman <[email protected]>

Co-authored-by: Andrew Suderman <[email protected]>
Co-authored-by: Andrew Suderman <[email protected]>
  • Loading branch information
3 people authored Jun 3, 2022
1 parent 2e37019 commit 2d64fbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ func init() {
klog.Exitf("Failed to bind show-errored-containers flag: %v", err)
}

rootCmd.PersistentFlags().Bool("show-old", false, "Only show charts that are not on the latest version")
err = viper.BindPFlag("show-old", rootCmd.PersistentFlags().Lookup("show-old"))
if err != nil {
klog.Exitf("Failed to bind show-old flag: %v", err)
}

klog.InitFlags(nil)
_ = flag.Set("alsologtostderr", "true")
_ = flag.Set("logtostderr", "true")
Expand Down Expand Up @@ -297,7 +303,7 @@ var findCmd = &cobra.Command{
klog.Exitf("error outputting to file: %s", err)
}
} else {
out.Print(viper.GetBool("wide"))
out.Print(viper.GetBool("wide"), viper.GetBool("show-old"))
}
},
}
Expand Down
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Global Flags:
--logtostderr log to standard error instead of files (default true)
--output-file string Path on local filesystem to write file output to
--poll-artifacthub When true, polls artifacthub to match against helm releases in the cluster. If false, you must provide a url list via --url/-u. Default is true. (default true)
--show-old Only output charts that are not on the latest version
-u, --url strings URL for a helm chart repo
-v, --v Level number for the log level verbosity
--wide Output chart name and namespace
Expand Down
4 changes: 2 additions & 2 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (output Output) ToFile(filename string) error {
}

// Print sends the output to STDOUT
func (output Output) Print(wide bool) {
func (output Output) Print(wide, showOld bool) {
if len(output.HelmReleases) == 0 {
fmt.Println("No releases found")
return
Expand All @@ -128,7 +128,7 @@ func (output Output) Print(wide bool) {
fmt.Fprintln(w, separator)

for _, release := range output.HelmReleases {
if !output.IncludeAll && release.Latest.Version == "" {
if (!output.IncludeAll && release.Latest.Version == "") || (showOld && !release.IsOld) {
continue
}
line := release.ReleaseName + "\t"
Expand Down

0 comments on commit 2d64fbc

Please sign in to comment.