From 49d7c7c0ee799a08b808bd9e5ca27681ce2ef96f Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Fri, 14 Sep 2018 11:51:01 -0700 Subject: [PATCH] Suppress usage upon Run error I changed RunE to Run so that usage wouldn't show upon error. Usage will still show if PersistentPreRunE fails, which makes sense since those functions check to make sure arguments passed in are valid. Also changed logging of multi arg flags to Debugf so that output would be cleaner. --- cmd/executor/cmd/root.go | 18 +++++++++++++----- pkg/config/args.go | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/executor/cmd/root.go b/cmd/executor/cmd/root.go index 97511e092..e5e0f8647 100644 --- a/cmd/executor/cmd/root.go +++ b/cmd/executor/cmd/root.go @@ -17,6 +17,7 @@ limitations under the License. package cmd import ( + "fmt" "os" "path/filepath" "strings" @@ -59,21 +60,23 @@ var RootCmd = &cobra.Command{ } return resolveDockerfilePath() }, - RunE: func(cmd *cobra.Command, args []string) error { + Run: func(cmd *cobra.Command, args []string) { if !checkContained() { if !force { - return errors.New("kaniko should only be run inside of a container, run with the --force flag if you are sure you want to continue") + exit(errors.New("kaniko should only be run inside of a container, run with the --force flag if you are sure you want to continue")) } logrus.Warn("kaniko is being run outside of a container. This can have dangerous effects on your system") } if err := os.Chdir("/"); err != nil { - return errors.Wrap(err, "error changing to root dir") + exit(errors.Wrap(err, "error changing to root dir")) } image, err := executor.DoBuild(opts) if err != nil { - return errors.Wrap(err, "error building image") + exit(errors.Wrap(err, "error building image")) + } + if err := executor.DoPush(image, opts); err != nil { + exit(errors.Wrap(err, "error pushing image")) } - return executor.DoPush(image, opts) }, } @@ -158,3 +161,8 @@ func resolveSourceContext() error { logrus.Debugf("Build context located at %s", opts.SrcContext) return nil } + +func exit(err error) { + fmt.Println(err) + os.Exit(1) +} diff --git a/pkg/config/args.go b/pkg/config/args.go index ae45b266c..44ac074e3 100644 --- a/pkg/config/args.go +++ b/pkg/config/args.go @@ -34,7 +34,7 @@ func (b *multiArg) String() string { // The second method is Set(value string) error func (b *multiArg) Set(value string) error { - logrus.Infof("appending to multi args %s", value) + logrus.Debugf("appending to multi args %s", value) *b = append(*b, value) return nil }