Cobra 是 Go 的 CLI 框架
注意
package main
import (
"fmt"
"github.com/spf13/cobra"
)
func main() {
var startCmd = &cobra.Command{
Use: "version",
Short: "this is a test version",
Long: "all application has a version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("start -- HEAD",args)
},
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "this is a test version",
Long: "all application has a version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("version1.0 -- ",args)
},
}
startCmd.AddCommand(versionCmd)
_ = startCmd.Execute()
}
参考:https://juejin.cn/post/6924541628031959047