x-mod/cmd 空格隔离参数

最后更新于:2022-04-02 02:39:09

[TOC] ## 实例 ### 只有root命令 ``` import ( "fmt" "github.com/x-mod/cmd" ) func main() { cmd.Add( cmd.Name("root"), cmd.Main(Main), ) cmd.Execute() } func Main(c *cmd.Command, args []string) error { fmt.Println("my root command running ...") return nil } ``` 运行 ``` $: go run main.go my root command running ... ``` ### 含有子命令 `cmd.Path("/")` 根命令 `cmd.Parent("/foo/bar")` 三级命令 subcommand's `cmd.Parent("/command/path")` must be setting. ``` import ( "fmt" "github.com/x-mod/cmd" ) func main() { cmd.Add( cmd.Path("/foo/bar/v1"), cmd.Main(V1), ).PersistentFlags().StringP("parameter", "p", "test", "flags usage") cmd.Version("version string") cmd.Execute() } func V1(c *cmd.Command, args []string) error { fmt.Println("V1 called") return nil } ``` 运行 ``` $: go run main.go foo bar v1 V1 called ```
';