Skip to content

Commit

Permalink
Suppress usage upon Run error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Priya Wadhwa committed Sep 14, 2018
1 parent 14f3c81 commit 49d7c7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package cmd

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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)
},
}

Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/config/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 49d7c7c

Please sign in to comment.