Documentation ¶
Overview ¶
Package cmdopt 用于创建子命令功能的命令行
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdOpt ¶
type CmdOpt struct {
// contains filtered or unexported fields
}
CmdOpt 带子命令的命令行操作
func New ¶
func New(output io.Writer, errorHandling flag.ErrorHandling, usageTemplate string, cmd CommandFunc, notFound func(string) string) *CmdOpt
New 声明带有子命令的命令行处理对象
output 表示命令行信息的输出通道;
errorHandling 表示出错时的处理方式;
cmd 非子命令的参数设定,可以为空;
usageTemplate 命令行的文字说明模板,包含了以下几个占位符:
- {{flags}} 参数说明,输出时被参数替换,如果没有可以为空;
- {{commands}} 子命令说明,输出时被子命令列表替换,如果没有可以为空;
notFound 表示找不到子命令时需要返回的文字说明,若为空,则采用 usageTemplate 处理后的内容;
func (*CmdOpt) New ¶
func (opt *CmdOpt) New(name, title, usage string, cmd CommandFunc)
New 注册一条新的子命令
name 为子命令的名称,必须唯一; cmd 为该条子命令执行的函数体; usage 为该条子命令的帮助内容。可以包含 {{flags}} 占位符,表示参数信息。
type CommandFunc ¶ added in v0.10.0
CommandFunc 子命令的初始化方法
FlagSet 可用于绑定各个命令行参数; 返回值 DoFunc 表示实际执行的函数;
type FlagSet ¶ added in v0.8.0
type FlagSet interface { Arg(i int) string Args() []string Bool(name string, value bool, usage string) *bool BoolVar(p *bool, name string, value bool, usage string) Duration(name string, value time.Duration, usage string) *time.Duration DurationVar(p *time.Duration, name string, value time.Duration, usage string) Float64(name string, value float64, usage string) *float64 Float64Var(p *float64, name string, value float64, usage string) Func(name, usage string, fn func(string) error) Int(name string, value int, usage string) *int Int64(name string, value int64, usage string) *int64 Int64Var(p *int64, name string, value int64, usage string) IntVar(p *int, name string, value int, usage string) Lookup(name string) *flag.Flag NArg() int NFlag() int Name() string Output() io.Writer Set(name, value string) error String(name string, value string, usage string) *string StringVar(p *string, name string, value string, usage string) TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, usage string) Uint(name string, value uint, usage string) *uint Uint64(name string, value uint64, usage string) *uint64 Uint64Var(p *uint64, name string, value uint64, usage string) UintVar(p *uint, name string, value uint, usage string) Var(value flag.Value, name string, usage string) Visit(fn func(*flag.Flag)) VisitAll(fn func(*flag.Flag)) }
FlagSet 这是 flag.FlagSet 的子集
Click to show internal directories.
Click to hide internal directories.