diff --git a/cmd/history.go b/cmd/history.go index fe5a837..b2e13e7 100644 --- a/cmd/history.go +++ b/cmd/history.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/appuio/seiso/cfg" "github.com/appuio/seiso/pkg/cleanup" "github.com/appuio/seiso/pkg/git" @@ -12,13 +13,15 @@ import ( var ( historyCmd = &cobra.Command{ - Use: "history [IMAGE]", - Aliases: []string{"hist"}, - Short: "Clean up excessive image tags", - Long: `Clean up excessive image tags matching the commit hashes (prefix) of the git repository`, - Args: cobra.MinimumNArgs(1), + Use: "history [PROJECT/IMAGE]", + Aliases: []string{"hist"}, + Short: "Clean up excessive image tags", + Long: `Clean up excessive image tags matching the commit hashes (prefix) of the git repository`, + Args: cobra.ExactArgs(1), + SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { if err := validateHistoryCommandInput(args); err != nil { + cmd.Usage() return err } return ExecuteHistoryCleanupCommand(args) @@ -46,6 +49,7 @@ func validateHistoryCommandInput(args []string) error { return nil } +// ExecuteHistoryCleanupCommand executes the history cleanup command func ExecuteHistoryCleanupCommand(args []string) error { c := config.History diff --git a/cmd/orphans.go b/cmd/orphans.go index 5b41089..b5821d8 100644 --- a/cmd/orphans.go +++ b/cmd/orphans.go @@ -3,6 +3,10 @@ package cmd import ( "errors" "fmt" + "regexp" + "strings" + "time" + "github.com/appuio/seiso/cfg" "github.com/appuio/seiso/pkg/cleanup" "github.com/appuio/seiso/pkg/git" @@ -10,9 +14,6 @@ import ( "github.com/karrick/tparse" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "regexp" - "strings" - "time" ) const ( @@ -26,13 +27,15 @@ var ( // orphanCmd represents a cobra command to clean up images by comparing the git commit history. It removes any // image tags that are not found in the git history by given criteria. orphanCmd = &cobra.Command{ - Use: "orphans [IMAGE]", - Short: "Clean up unknown image tags", - Long: orphanCommandLongDescription, - Aliases: []string{"orph"}, - Args: cobra.MinimumNArgs(1), + Use: "orphans [PROJECT/IMAGE]", + Short: "Clean up unknown image tags", + Long: orphanCommandLongDescription, + Aliases: []string{"orph"}, + Args: cobra.ExactArgs(1), + SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { if err := validateOrphanCommandInput(args); err != nil { + cmd.Usage() return err } return ExecuteOrphanCleanupCommand(args) @@ -71,6 +74,7 @@ func validateOrphanCommandInput(args []string) error { return nil } +// ExecuteOrphanCleanupCommand executes the orphan cleanup command func ExecuteOrphanCleanupCommand(args []string) error { o := config.Orphan diff --git a/cmd/root.go b/cmd/root.go index 3119b35..362bcae 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,7 +16,7 @@ var ( // rootCmd represents the base command when called without any subcommands rootCmd = &cobra.Command{ Use: "seiso", - Short: "keeps your kubernetes projects clean", + Short: "Keeps your Kubernetes projects clean", PersistentPreRun: parseConfig, } config = cfg.NewDefaultConfig() diff --git a/main.go b/main.go index e7293ad..1b06fac 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,9 @@ package main import ( "fmt" + "os" "github.com/appuio/seiso/cmd" - log "github.com/sirupsen/logrus" ) var ( @@ -16,6 +16,6 @@ var ( func main() { cmd.SetVersion(fmt.Sprintf("%s, commit %s, date %s", version, commit, date)) if err := cmd.Execute(); err != nil { - log.WithError(err).Fatal("Command aborted.") + os.Exit(1) } }