From befe3c31d1f74465873dc8004ccc55a9e13faedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20R=C3=BCegg?= Date: Mon, 30 Mar 2020 17:11:28 +0200 Subject: [PATCH] Remove redunant logs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the Cobra framework logs errors of commands already, they don't need to be logged again in `main.go`. Signed-off-by: Simon Rüegg --- cmd/history.go | 14 +++++++++----- cmd/orphans.go | 20 ++++++++++++-------- cmd/root.go | 2 +- main.go | 4 ++-- 4 files changed, 24 insertions(+), 16 deletions(-) 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) } }