update flags

This commit is contained in:
Forest-L 2020-11-28 16:43:33 +08:00
parent 5607fee576
commit f3b47d9f57
4 changed files with 24 additions and 17 deletions

View File

@ -8,15 +8,9 @@ import (
"kubeye/pkg/validator" "kubeye/pkg/validator"
) )
func init() {
rootCmd.AddCommand(addCmd)
flag.Parse()
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
}
var addCmd = &cobra.Command{ var addCmd = &cobra.Command{
Use: "install ntp", Use: "install npd",
Short: "install the ntp", Short: "install the npd",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
err := validator.Add(cmd.Context()) err := validator.Add(cmd.Context())
if err != nil { if err != nil {
@ -24,3 +18,8 @@ var addCmd = &cobra.Command{
} }
}, },
} }
func init() {
rootCmd.AddCommand(addCmd)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
}

View File

@ -1,20 +1,15 @@
package cmd package cmd
import ( import (
"flag"
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag"
"kubeye/pkg/validator" "kubeye/pkg/validator"
) )
var config string 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{ var auditCmd = &cobra.Command{
Use: "audit", Use: "audit",
Short: "audit the result", 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")
}

View File

@ -21,9 +21,11 @@ import (
"os" "os"
) )
var Verbose bool
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "ke", Use: "ke",
Short: "kubeye the cluster configuration", Short: "Kubeye the cluster configuration",
} }
func Execute() { func Execute() {
@ -32,3 +34,6 @@ func Execute() {
os.Exit(1) os.Exit(1)
} }
} }
func init() {
rootCmd.PersistentFlags().BoolVar(&Verbose, "debug", true, "Print detailed information")
}

View File

@ -15,7 +15,9 @@ limitations under the License.
*/ */
package main package main
import "kubeye/cmd" import (
"kubeye/cmd"
)
func main() { func main() {
cmd.Execute() cmd.Execute()