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.
This commit is contained in:
parent
14f3c81b79
commit
49d7c7c0ee
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue