package main import ( "fmt" "go_dreamfactory/cmd/robot" "os" flag "github.com/spf13/pflag" "github.com/spf13/cobra" ) func emptyRun(*cobra.Command, []string) {} var RootCmd = &cobra.Command{ Use: "robot", Short: "命令行", Long: "命令行工具", Run: emptyRun, } func Execute() { if err := RootCmd.Execute(); err != nil { fmt.Fprintln(os.Stdin, err) os.Exit(1) } } func init() { RootCmd.AddCommand(runCmd) } var account = flag.String("account", "", "account") var create = flag.Bool("create", false, "account") //false 不创建新账号 func main() { Execute() } var runCmd = &cobra.Command{ Use: "run", Short: "启动", Run: func(cmd *cobra.Command, args []string) { opts := robot.DefaultOpts() opts.Create = *create if *create { opts.Account = *account } r := robot.NewRobot(opts) r.Run() }, }