Go每日一库 - cobra
Cobra功能 简单子命令cli 如 kubectl verion kubectl get 自动识别-h,–help 帮助 更过参考官方手册:https://github.com/spf13/cobra kubectl get pod --all-namespaces get 代表命令(command) pod 代表事务(args) --all-namespaces 代表标识(flag) command 代表动作, Args 代表事务, flags 代表动作的修饰符。 使用Cobra 使用cobra需要main.go或和cmd/cmd.go(非固定,根据官方手册说明操作的),来创建需要添加的命令。 cobra不需要构造函数,只需要创建命令即可 go 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 rootCmd = &cobra.Command{ Use: "db ", Short: "test1", Long: `this is a test123`, Run: func(cmd *cobra.Command, args []string) { log.Println(cfgFile, port) }, } func Execute() { if err := rootCmd....