Documentation ¶
Overview ¶
Package flag is used to wrap some APIs from go stdlib flag
Index ¶
- func Args() []string
- func Bool(name string, value bool, usage string, options ...Option) *bool
- func BoolVar(p *bool, name string, value bool, usage string, options ...Option)
- func Duration(name string, value time.Duration, usage string, options ...Option) *time.Duration
- func DurationVar(p *time.Duration, name string, value time.Duration, usage string, ...)
- func Float32(name string, value float32, usage string, options ...Option) *float32
- func Float32Var(p *float32, name string, value float32, usage string, options ...Option)
- func Float64(name string, value float64, usage string, options ...Option) *float64
- func Float64Var(p *float64, name string, value float64, usage string, options ...Option)
- func Int(name string, value int, usage string, options ...Option) *int
- func Int64(name string, value int64, usage string, options ...Option) *int64
- func Int64Var(p *int64, name string, value int64, usage string, options ...Option)
- func IntSlice(name string, value []int, usage string, options ...Option) *[]int
- func IntSliceVar(p *[]int, name string, value []int, usage string, options ...Option)
- func IntVar(p *int, name string, value int, usage string, options ...Option)
- func NArg() int
- func Parse()
- func Parsed() bool
- func String(name string, value string, usage string, options ...Option) *string
- func StringSlice(name string, value []string, usage string, options ...Option) *[]string
- func StringSliceVar(p *[]string, name string, value []string, usage string, options ...Option)
- func StringVar(p *string, name string, value string, usage string, options ...Option)
- func TreatAsLongOpt(b bool) bool
- func Uint(name string, value uint, usage string, options ...Option) *uint
- func Uint64(name string, value uint64, usage string, options ...Option) *uint64
- func Uint64Var(p *uint64, name string, value uint64, usage string, options ...Option)
- func UintVar(p *uint, name string, value uint, usage string, options ...Option)
- type Option
- func WithAction(action func(cmd *cmdr.Command, args []string) (err error)) (opt Option)
- func WithAliases(aliases ...string) (opt Option)
- func WithCommand(cmdDefines func(newSubCmd cmdr.OptCmd)) (opt Option)
- func WithDefaultValue(val interface{}, placeholder string) (opt Option)
- func WithDeprecated(deprecation string) (opt Option)
- func WithDescription(oneLine, long string) (opt Option)
- func WithEnvKeys(keys ...string) (opt Option)
- func WithExamples(examples string) (opt Option)
- func WithExternalTool(envKeyName string) (opt Option)
- func WithGroup(group string) (opt Option)
- func WithHeadLike(enable bool, min, max int64) (opt Option)
- func WithHidden(hidden bool) (opt Option)
- func WithLong(long string) (opt Option)
- func WithOnSet(f func(keyPath string, value interface{})) (opt Option)
- func WithShort(short string) (opt Option)
- func WithTitles(short, long string, aliases ...string) (opt Option)
- func WithToggleGroup(group string) (opt Option)
- func WithValidArgs(list ...string) (opt Option)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.
func BoolVar ¶
BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.
func Duration ¶
Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag. The flag accepts a value acceptable to time.ParseDuration.
func DurationVar ¶
func DurationVar(p *time.Duration, name string, value time.Duration, usage string, options ...Option)
DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag. The flag accepts a value acceptable to time.ParseDuration.
func Float32 ¶ added in v1.1.5
Float32 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.
func Float32Var ¶ added in v1.1.5
Float32Var defines a float32 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.
func Float64 ¶
Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.
func Float64Var ¶
Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.
func Int ¶
Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.
func Int64 ¶
Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.
func Int64Var ¶
Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.
func IntSlice ¶ added in v1.0.6
IntSlice defines a int slice flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.
func IntSliceVar ¶ added in v1.0.6
IntSliceVar defines a int slice flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.
func IntVar ¶
IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.
func NArg ¶ added in v1.6.11
func NArg() int
NArg returns the count of non-flag command-line arguments.
func Parse ¶
func Parse()
Parse parses the command-line flags from os.Args[1:]. Must be called after all flags are defined and before flags are accessed by the program.
func String ¶
String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.
func StringSlice ¶ added in v1.0.6
StringSlice defines a string slice flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.
func StringSliceVar ¶ added in v1.0.6
StringSliceVar defines a string slice flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.
func StringVar ¶
StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.
func TreatAsLongOpt ¶
TreatAsLongOpt treat name as long option name or short.
func Uint ¶
Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.
func Uint64 ¶
Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.
Types ¶
type Option ¶
Option is used by cmdr fluent API and flag compatible API
func WithAction ¶
WithAction to specify the action as the option was matched
func WithAliases ¶
WithAliases sets the aliases string list
func WithCommand ¶ added in v1.0.5
WithCommand define an (Sub-)Command
func WithDefaultValue ¶
WithDefaultValue set the value with explicit data type, and its placeholder name.
func WithDeprecated ¶
WithDeprecated sets a version string for an deprecation option
func WithDescription ¶
WithDescription sets the description string
func WithEnvKeys ¶ added in v1.6.21
WithEnvKeys binds the environ variable keynames to an option.
func WithExamples ¶
WithExamples sets the example string for an option
func WithExternalTool ¶
WithExternalTool allows launch an external program via an environment key yours specified. for example, while you setup by `WithExternalTool("EDITOR")`, cmdr will lookup it from os environment and launch that program. for EDITOR=vim, `vim` will be launched.
func WithHeadLike ¶
WithHeadLike enables `head -n` mode. min, max will be ignored at this version, its might be impl in the future
func WithHidden ¶
WithHidden sets an hidden option that does not be displayed in any list or help screen.
func WithTitles ¶
WithTitles setup short title, long title, and aliases titles
func WithToggleGroup ¶
WithToggleGroup allows to specify an group name, and any options in this group will be treated as an toggleable group, just like raido button group.
func WithValidArgs ¶
WithValidArgs enables enumerable values for an option.