增加命令行参数解析
This commit is contained in:
parent
ab7c721175
commit
9584398b77
44
cli.go
Normal file
44
cli.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user