Documentation
¶
Index ¶
- Constants
- Variables
- func Any[T Types[K, V], K KeyTypes, V ElemTypes](fs *FlagSet, short byte, long string, dft T, desc string, opts ...Options) *T
- func AnyVar[T Types[K, V], K KeyTypes, V ElemTypes](fs *FlagSet, ptr *T, short byte, long string, dft T, desc string, ...)
- func CurrentCommandUsage(ctx context.Context) string
- func Map[K KeyTypes, V ElemTypes](fs *FlagSet, short byte, long string, dft map[K]V, desc string, ...) *map[K]V
- func MapSlice[K KeyTypes, V ElemTypes](fs *FlagSet, short byte, long string, dft map[K][]V, desc string, ...) *map[K][]V
- func MapSliceVar[K KeyTypes, V ElemTypes](fs *FlagSet, ptr *map[K][]V, short byte, long string, dft map[K][]V, ...)
- func MapVar[K KeyTypes, V ElemTypes](fs *FlagSet, ptr *map[K]V, short byte, long string, dft map[K]V, desc string, ...)
- func Slice[T ElemTypes](fs *FlagSet, short byte, long string, dft []T, desc string, opts ...Options) *[]T
- func SliceMap[K KeyTypes, V ElemTypes](fs *FlagSet, short byte, long string, dft []map[K]V, desc string, ...) *[]map[K]V
- func SliceMapVar[K KeyTypes, V ElemTypes](fs *FlagSet, ptr *[]map[K]V, short byte, long string, dft []map[K]V, ...)
- func SliceVar[T ElemTypes](fs *FlagSet, ptr *[]T, short byte, long string, dft []T, desc string, ...)
- func ValidLong(long string) bool
- func ValidShort(short byte) bool
- type ComTypes
- type ElemTypes
- type FlagSet
- func (fs *FlagSet) AnyVar(ptr any, short byte, long string, dft any, desc string, opts ...Options)
- func (fs *FlagSet) Bool(short byte, long string, dft bool, desc string, opts ...Options) *bool
- func (fs *FlagSet) BoolVar(ptr *bool, short byte, long string, dft bool, desc string, opts ...Options)
- func (fs *FlagSet) Cmd(name, desc string, mws ...Middleware) *FlagSet
- func (fs *FlagSet) DateTime(short byte, long string, dft time.Time, desc string, opts ...Options) *time.Time
- func (fs *FlagSet) DateTimeVar(ptr *time.Time, short byte, long string, dft time.Time, desc string, ...)
- func (fs *FlagSet) Duration(short byte, long string, dft time.Duration, desc string, opts ...Options) *time.Duration
- func (fs *FlagSet) DurationVar(ptr *time.Duration, short byte, long string, dft time.Duration, desc string, ...)
- func (fs *FlagSet) Float32(short byte, long string, dft float32, desc string, opts ...Options) *float32
- func (fs *FlagSet) Float32Var(ptr *float32, short byte, long string, dft float32, desc string, ...)
- func (fs *FlagSet) Float64(short byte, long string, dft float64, desc string, opts ...Options) *float64
- func (fs *FlagSet) Float64Var(ptr *float64, short byte, long string, dft float64, desc string, ...)
- func (fs *FlagSet) Handle(h Handler, mws ...Middleware)
- func (fs *FlagSet) Int(short byte, long string, dft int, desc string, opts ...Options) *int
- func (fs *FlagSet) Int16(short byte, long string, dft int16, desc string, opts ...Options) *int16
- func (fs *FlagSet) Int16Var(ptr *int16, short byte, long string, dft int16, desc string, opts ...Options)
- func (fs *FlagSet) Int32(short byte, long string, dft int32, desc string, opts ...Options) *int32
- func (fs *FlagSet) Int32Var(ptr *int32, short byte, long string, dft int32, desc string, opts ...Options)
- func (fs *FlagSet) Int64(short byte, long string, dft int64, desc string, opts ...Options) *int64
- func (fs *FlagSet) Int64Var(ptr *int64, short byte, long string, dft int64, desc string, opts ...Options)
- func (fs *FlagSet) Int8(short byte, long string, dft int8, desc string, opts ...Options) *int8
- func (fs *FlagSet) Int8Var(ptr *int8, short byte, long string, dft int8, desc string, opts ...Options)
- func (fs *FlagSet) IntVar(ptr *int, short byte, long string, dft int, desc string, opts ...Options)
- func (fs *FlagSet) Parsed(pointer any) bool
- func (fs *FlagSet) Run(ctx context.Context, args ...string) (string, error)
- func (fs *FlagSet) RunCmdline(ctx context.Context)
- func (fs *FlagSet) Stmt(mws ...Middleware) *FlagSet
- func (fs *FlagSet) Str(short byte, long string, dft string, desc string, opts ...Options) *string
- func (fs *FlagSet) StrVar(ptr *string, short byte, long string, dft string, desc string, opts ...Options)
- func (fs *FlagSet) Uint(short byte, long string, dft uint, desc string, opts ...Options) *uint
- func (fs *FlagSet) Uint16(short byte, long string, dft uint16, desc string, opts ...Options) *uint16
- func (fs *FlagSet) Uint16Var(ptr *uint16, short byte, long string, dft uint16, desc string, opts ...Options)
- func (fs *FlagSet) Uint32(short byte, long string, dft uint32, desc string, opts ...Options) *uint32
- func (fs *FlagSet) Uint32Var(ptr *uint32, short byte, long string, dft uint32, desc string, opts ...Options)
- func (fs *FlagSet) Uint64(short byte, long string, dft uint64, desc string, opts ...Options) *uint64
- func (fs *FlagSet) Uint64Var(ptr *uint64, short byte, long string, dft uint64, desc string, opts ...Options)
- func (fs *FlagSet) Uint8(short byte, long string, dft uint8, desc string, opts ...Options) *uint8
- func (fs *FlagSet) Uint8Var(ptr *uint8, short byte, long string, dft uint8, desc string, opts ...Options)
- func (fs *FlagSet) UintVar(ptr *uint, short byte, long string, dft uint, desc string, opts ...Options)
- func (fs *FlagSet) Usage() string
- func (fs *FlagSet) Use(mws ...Middleware) *FlagSet
- type Handler
- type KeyTypes
- type Middleware
- type Options
- type Types
Constants ¶
const ( NoShort byte = 0 // 不设置短参数 NoLong string = "" // 不设置长参数 )
const DateTime = "2006-01-02T15:04:05"
时间参数格式
Variables ¶
Functions ¶
func CurrentCommandUsage ¶
CurrentCommandUsage:当前命令用法
func MapSliceVar ¶
func SliceMapVar ¶
func ValidShort ¶
Types ¶
type FlagSet ¶
type FlagSet struct {
// contains filtered or unexported fields
}
FlagSet提供一组参数解析/命令执行的绑定关系。不可复用,如需要重复解析,需重新生成新的FlagSet。
func (*FlagSet) AnyVar ¶
AnyVar: add any pointer to parse. param ptr must be a pointer, param dft should be nil if no default value, or else dft type must be reflect.TypeOf(ptr).Elem().
func (*FlagSet) Cmd ¶
func (fs *FlagSet) Cmd(name, desc string, mws ...Middleware) *FlagSet
Cmd:注册子命令,及子命令用到的中间件。
func (*FlagSet) DateTimeVar ¶
func (*FlagSet) DurationVar ¶
func (*FlagSet) Float32Var ¶
func (*FlagSet) Float64Var ¶
func (*FlagSet) Handle ¶
func (fs *FlagSet) Handle(h Handler, mws ...Middleware)
Handle:设置Handler,并可以同时设置该handler的中间件
func (*FlagSet) Run ¶
Run:解析参数,并调用子命令handler。常见用法为:`fs.Run(context.Background(), os.Args[1:]...)`。 返回Usage及错误信息。Usage保持不为空,业务可根据需要判断是否需要展示Usage。
func (*FlagSet) RunCmdline ¶
func (*FlagSet) Stmt ¶
func (fs *FlagSet) Stmt(mws ...Middleware) *FlagSet
Stmt:开启一个单独的状态,可用于注册特定中间件,不影响Stmt之后的命令。
func (*FlagSet) Use ¶
func (fs *FlagSet) Use(mws ...Middleware) *FlagSet
Use:设置中间件,所有以后注册的Handler会用到该中间件
type Middleware ¶
type Options ¶
type Options interface {
// contains filtered or unexported methods
}
Options:设置参数规则。 可选值有WithSliceSeperator、WithKeyValueSeperator、WithZeroDefault。
func WithKeyValueSeperator ¶
WithKeyValueSeperator:key/value切分规则,默认为":"。 应先设置WithSliceSeperator切分为kv对,再用kv seperator切分key/value值。
func WithSliceSeperator ¶
WithSliceSeperator:数组切分规则,默认为","。 用于map结构时,先以slice seperator切分成kv对,再用kv seperator切分key/value值。
func WithZeroDefault ¶
WithZeroDefault:是否显示默认零值。 比如int参数为零值0时,将不在help中显示"(default: 0)"。 可设置该参数强制显示。