diff --git a/cli.go b/cli.go new file mode 100644 index 0000000..97d4341 --- /dev/null +++ b/cli.go @@ -0,0 +1,44 @@ +// Package command ... +// +// Description : command ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2022-06-28 19:33 +package command + +import ( + "flag" + + "git.zhangdeman.cn/zhangdeman/command/define" + "git.zhangdeman.cn/zhangdeman/util" +) + +// Cli 获取CLI实例 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 19:34 2022/6/28 +func Cli(paramList []*define.CliParam) *cli { + return &cli{paramList: paramList} +} + +type cli struct { + paramList []*define.CliParam +} + +// Parse 解析命令行参数 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 19:34 2022/6/28 +func (c *cli) Parse() error { + for _, item := range c.paramList { + inputValue := flag.String(item.Name, item.DefaultValue, item.Description) + if err := util.ConvertAssign(item.Receiver, *inputValue); nil != err { + return err + } + } + flag.Parse() + return nil +}