package cmd import ( "errors" "fmt" "github.com/spf13/cobra" "os" ) var rootCmd = &cobra.Command{ Use: "flytalk", Short: "flytalk", Long: `Fast online message service`, Args: args, Run: func(cmd *cobra.Command, args []string) { }, } func args(cmd *cobra.Command, args []string) error { if len(args) < 1 { return errors.New("At least one argument is needed") } return nil } func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } } func init() { //serverCmd.PersistentFlags().StringVarP(&Addr, "addr", "a", "127.0.0.1:10016", "server address listening on") serverCmd.PersistentFlags().StringVarP(&Confile, "config", "c", "flytalk.toml", "specify the config file") //serverCmd.PersistentFlags().BoolVarP(&Daemon, "daemon", "d", false, "run in daemon mode") installCmd.PersistentFlags().StringVarP(&Confile, "config", "c", "flytalk.toml", "specify the config file") testCmd.PersistentFlags().StringVarP(&Confile, "config", "c", "flytalk.toml", "specify the tested config file") rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(serverCmd) rootCmd.AddCommand(installCmd) rootCmd.AddCommand(testCmd) }