From 51c972ad3360994139f2f113ff4f085ffa03b5cc Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Fri, 22 May 2020 15:25:49 -0400 Subject: [PATCH] add exit on cli bind fails + copy update --- cmd/cli.go | 6 +++++- internal/config/config.go | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/cli.go b/cmd/cli.go index 1a4e4c1a3..329c1cc5c 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/anchore/imgbom/imgbom/presenter" "github.com/anchore/imgbom/imgbom/scope" @@ -21,6 +22,7 @@ func setCliOptions() { fmt.Sprintf("selection of layers to analyze, options=%v", scope.Options)) if err := viper.BindPFlag(flag, rootCmd.Flags().Lookup(flag)); err != nil { fmt.Printf("unable to bind flag '%s': %+v", flag, err) + os.Exit(1) } // output & formatting options @@ -31,15 +33,17 @@ func setCliOptions() { ) if err := viper.BindPFlag(flag, rootCmd.Flags().Lookup(flag)); err != nil { fmt.Printf("unable to bind flag '%s': %+v", flag, err) + os.Exit(1) } flag = "quiet" rootCmd.Flags().BoolP( flag, "q", false, - "suppress all auxiliary output", + "suppress all logging output", ) if err := viper.BindPFlag(flag, rootCmd.Flags().Lookup(flag)); err != nil { fmt.Printf("unable to bind flag '%s': %+v", flag, err) + os.Exit(1) } rootCmd.Flags().CountVarP(&cliOpts.Verbosity, "verbose", "v", "increase verbosity (-v = info, -vv = debug)") diff --git a/internal/config/config.go b/internal/config/config.go index 85f913527..5493b2852 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -85,7 +85,9 @@ func (cfg *Application) Build() error { cfg.ScopeOpt = scopeOption if cfg.Quiet { - // quiet option trumps all other logging options + // TODO: this is bad: quiet option trumps all other logging options + // we should be able to quiet the consol logging and leave file logging alone... + // ... this will be an enhancement for later cfg.Log.LevelOpt = zapcore.PanicLevel } else { if cfg.Log.Level != "" {