Fix the `--exit-code` flag doesn't work when run with subcommand (#1084)

pull/1086/head
Huang Huang 2 years ago committed by GitHub
parent 9119968940
commit d232ae0fb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,7 @@ package cmd
import (
"fmt"
"os"
"github.com/aquasecurity/kube-bench/check"
"github.com/spf13/cobra"
@ -36,6 +37,7 @@ var masterCmd = &cobra.Command{
filename := loadConfig(check.MASTER, bv)
runChecks(check.MASTER, filename, detecetedKubeVersion)
writeOutput(controlsCollection)
os.Exit(exitCodeSelection(controlsCollection))
},
Deprecated: "this command will be retired soon. Please use the `run` command with `--targets=master` instead.",
}

@ -16,6 +16,7 @@ package cmd
import (
"fmt"
"os"
"github.com/aquasecurity/kube-bench/check"
"github.com/spf13/cobra"
@ -36,6 +37,7 @@ var nodeCmd = &cobra.Command{
filename := loadConfig(check.NODE, bv)
runChecks(check.NODE, filename, detecetedKubeVersion)
writeOutput(controlsCollection)
os.Exit(exitCodeSelection(controlsCollection))
},
Deprecated: "this command will be retired soon. Please use the `run` command with `--targets=node` instead.",
}

@ -136,8 +136,7 @@ var RootCmd = &cobra.Command{
}
writeOutput(controlsCollection)
exitCode := exitCodeSelection(controlsCollection)
os.Exit(exitCode)
os.Exit(exitCodeSelection(controlsCollection))
},
}

@ -54,13 +54,15 @@ var runCmd = &cobra.Command{
path := filepath.Join(cfgDir, bv)
err = mergeConfig(path)
if err != nil {
fmt.Printf("Error in mergeConfig: %v\n", err)
exitWithError(fmt.Errorf("Error in mergeConfig: %v\n", err))
}
err = run(targets, bv)
if err != nil {
fmt.Printf("Error in run: %v\n", err)
exitWithError(fmt.Errorf("Error in run: %v\n", err))
}
os.Exit(exitCodeSelection(controlsCollection))
},
}

Loading…
Cancel
Save