File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,11 @@ import (
55 "os"
66 "strings"
77
8- "github.com/jetstack/preflight/pkg/logs"
98 "github.com/spf13/cobra"
109 "github.com/spf13/pflag"
10+ "k8s.io/klog/v2"
11+
12+ "github.com/jetstack/preflight/pkg/logs"
1113)
1214
1315// rootCmd represents the base command when called without any subcommands
@@ -31,13 +33,16 @@ func init() {
3133
3234// Execute adds all child commands to the root command and sets flags appropriately.
3335// This is called by main.main(). It only needs to happen once to the rootCmd.
36+ // If the root command or sub-command returns an error, the error message will
37+ // will be logged and the process will exit with status 1.
3438func Execute () {
3539 logs .AddFlags (rootCmd .PersistentFlags ())
36-
40+ var exitCode int
3741 if err := rootCmd .Execute (); err != nil {
38- fmt . Println ( err )
39- os . Exit ( 1 )
42+ exitCode = 1
43+ klog . ErrorS ( err , "Exiting due to error" , "exit-code" , exitCode )
4044 }
45+ klog .FlushAndExit (klog .ExitFlushTimeout , exitCode )
4146}
4247
4348func setFlagsFromEnv (prefix string , fs * pflag.FlagSet ) {
You can’t perform that action at this time.
0 commit comments