From f3b47d9f57da856885f54e59a151e4ea2eff300b Mon Sep 17 00:00:00 2001 From: Forest-L Date: Sat, 28 Nov 2020 16:43:33 +0800 Subject: [PATCH] update flags --- cmd/add.go | 15 +++++++-------- cmd/audit.go | 15 ++++++++------- cmd/root.go | 7 ++++++- main.go | 4 +++- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index 503e9cb..cd50eb7 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -8,15 +8,9 @@ import ( "kubeye/pkg/validator" ) -func init() { - rootCmd.AddCommand(addCmd) - flag.Parse() - pflag.CommandLine.AddGoFlagSet(flag.CommandLine) -} - var addCmd = &cobra.Command{ - Use: "install ntp", - Short: "install the ntp", + Use: "install npd", + Short: "install the npd", Run: func(cmd *cobra.Command, args []string) { err := validator.Add(cmd.Context()) if err != nil { @@ -24,3 +18,8 @@ var addCmd = &cobra.Command{ } }, } + +func init() { + rootCmd.AddCommand(addCmd) + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) +} diff --git a/cmd/audit.go b/cmd/audit.go index 3a7af71..6163791 100644 --- a/cmd/audit.go +++ b/cmd/audit.go @@ -1,20 +1,15 @@ package cmd import ( + "flag" "fmt" "github.com/spf13/cobra" + "github.com/spf13/pflag" "kubeye/pkg/validator" ) var config string -func init() { - rootCmd.AddCommand(auditCmd) - //flag.Parse() - //pflag.CommandLine.AddGoFlagSet(flag.CommandLine) - auditCmd.Flags().StringVarP(&config, "filename", "f", "", "Customize best practice configuration") -} - var auditCmd = &cobra.Command{ Use: "audit", Short: "audit the result", @@ -25,3 +20,9 @@ var auditCmd = &cobra.Command{ } }, } + +func init() { + rootCmd.AddCommand(auditCmd) + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + auditCmd.Flags().StringVarP(&config, "filename", "f", "", "Customize best practice configuration") +} diff --git a/cmd/root.go b/cmd/root.go index a937d92..449f141 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,9 +21,11 @@ import ( "os" ) +var Verbose bool + var rootCmd = &cobra.Command{ Use: "ke", - Short: "kubeye the cluster configuration", + Short: "Kubeye the cluster configuration", } func Execute() { @@ -32,3 +34,6 @@ func Execute() { os.Exit(1) } } +func init() { + rootCmd.PersistentFlags().BoolVar(&Verbose, "debug", true, "Print detailed information") +} diff --git a/main.go b/main.go index cd0a9d9..247f186 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,9 @@ limitations under the License. */ package main -import "kubeye/cmd" +import ( + "kubeye/cmd" +) func main() { cmd.Execute()