From 00d8660a91c3b2156c0eed13d1462b88ebaa5ad8 Mon Sep 17 00:00:00 2001 From: Bezalel Brandwine Date: Thu, 14 Oct 2021 10:46:42 +0300 Subject: [PATCH] fix --help flag --- cmd/root.go | 10 +++++++--- cmd/scan.go | 2 -- main.go | 3 --- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index c760e45a..7f51c38a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,10 +13,17 @@ import ( var cfgFile string var armoBEURLs = "" +const envFlagUsage = "Send report results to specific URL. Format:,,.\n\t\tExample:report.armo.cloud,api.armo.cloud,portal.armo.cloud" + var rootCmd = &cobra.Command{ Use: "kubescape", Short: "Kubescape is a tool for testing Kubernetes security posture", Long: `Kubescape is a tool for testing Kubernetes security posture based on NSA \ MITRE ATT&CKĀ® specifications.`, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + flag.Parse() + InitArmoBEConnector() + return nil + }, } func Execute() { @@ -36,9 +43,6 @@ func initConfig() { } func InitArmoBEConnector() { - if armoBEURLs == "" && rootCmd.Flag("environment") != nil { - armoBEURLs = rootCmd.Flag("environment").Value.String() - } urlSlices := strings.Split(armoBEURLs, ",") if len(urlSlices) > 3 { glog.Errorf("Too many URLs") diff --git a/cmd/scan.go b/cmd/scan.go index ca14f8e3..e421f852 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -4,8 +4,6 @@ import ( "github.com/spf13/cobra" ) -const envFlagUsage = "Send report results to specific URL. Format:,,.\n\t\tExample:report.armo.cloud,api.armo.cloud,portal.armo.cloud" - // scanCmd represents the scan command var scanCmd = &cobra.Command{ Use: "scan", diff --git a/main.go b/main.go index 6565b817..114f855c 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "flag" "fmt" "os" @@ -10,8 +9,6 @@ import ( func main() { CheckLatestVersion() - flag.Parse() - cmd.InitArmoBEConnector() cmd.Execute() }