Documentation
¶
Index ¶
- Variables
- func FlagValue(typ reflect.Type, val reflect.Value) (flag.Value, error)
- func ParseArgs(sortedShort []PrefixedFlag, sortedLong []PrefixedFlag, args []string, ...) (remaining []string, err error)
- func ParseIPv4Mask(s string) net.IPMask
- func ParseLongArg(sortedFlags []PrefixedFlag, firstArg string, args []string, fn ApplyArg) (nextArgs []string, err error)
- func ParseShortArg(sortedFlags []PrefixedFlag, firstArg string, args []string, fn ApplyArg) (nextArgs []string, err error)
- func Run(cmd interface{})
- type ApplyArg
- type BoolSliceValue
- type BoolValue
- type BytesHexFlag
- type ChangedMarkers
- type Command
- type CommandDescription
- func (descr *CommandDescription) Execute(ctx context.Context, opts *ExecutionOptions, args ...string) (final *CommandDescription, err error)
- func (descr *CommandDescription) Load(val interface{}) error
- func (descr *CommandDescription) LoadReflect(val reflect.Value) error
- func (descr *CommandDescription) Usage(showHidden bool) string
- type CommandKnownRoutes
- type CommandRoute
- type DurationSliceValue
- type DurationValue
- type ExecutionOptions
- type Flag
- type FlagGroup
- type Float32SliceValue
- type Float32Value
- type Float64SliceValue
- type Float64Value
- type Help
- type IPMaskValue
- type IPNetValue
- type IPSliceValue
- type IPValue
- type ImplicitValue
- type InitDefault
- type InlineHelp
- type Int16SliceValue
- type Int16Value
- type Int32SliceValue
- type Int32Value
- type Int64SliceValue
- type Int64Value
- type Int8SliceValue
- type Int8Value
- type IntSliceValue
- type IntValue
- type PrefixedFlag
- type StringSliceValue
- type StringValue
- type TypedValue
- type Uint16SliceValue
- type Uint16Value
- type Uint32SliceValue
- type Uint32Value
- type Uint64SliceValue
- type Uint64Value
- type Uint8Value
- type UintSliceValue
- type UintValue
Constants ¶
This section is empty.
Variables ¶
var HelpErr = errors.New("ask: help asked with flag")
var UnrecognizedErr = errors.New("command was not recognized")
Functions ¶
func ParseArgs ¶ added in v0.1.0
func ParseArgs(sortedShort []PrefixedFlag, sortedLong []PrefixedFlag, args []string, set ApplyArg) (remaining []string, err error)
ParseArgs parses arguments as flags (long and short format). Not all arguments may be consumed as flags, the remaining arguments are returned. Unrecognized flags result in an error. A HelpErr is returned if a flag like `--help` or `-h` is detected.
func ParseIPv4Mask ¶ added in v0.1.0
ParseIPv4Mask written in IP form (e.g. 255.255.255.0). This function should really belong to the net package.
func ParseLongArg ¶ added in v0.1.0
func ParseLongArg(sortedFlags []PrefixedFlag, firstArg string, args []string, fn ApplyArg) (nextArgs []string, err error)
ParseLongArg parses an argument as long-flag. It may consume more arguments: remaining arguments to parse next are returned. A HelpErr is returned when a flag is detected like `--help`.
The sortedFlags slice is ordered from low to high long string.
func ParseShortArg ¶ added in v0.1.0
func ParseShortArg(sortedFlags []PrefixedFlag, firstArg string, args []string, fn ApplyArg) (nextArgs []string, err error)
ParseShortArg parses an argument as shorthand(s) string. It may consume more arguments: remaining arguments to parse next are returned. A HelpErr is returned when a flag is detected like `-h`.
The sortedFlags slice is ordered from low to high shorthand string
Types ¶
type ApplyArg ¶ added in v0.1.0
type ApplyArg func(fl PrefixedFlag, value string) error
type BoolSliceValue ¶ added in v0.1.0
type BoolSliceValue []bool
func (*BoolSliceValue) Set ¶ added in v0.1.0
func (s *BoolSliceValue) Set(val string) error
func (*BoolSliceValue) String ¶ added in v0.1.0
func (s *BoolSliceValue) String() string
func (*BoolSliceValue) Type ¶ added in v0.1.0
func (s *BoolSliceValue) Type() string
type BytesHexFlag ¶ added in v0.0.2
type BytesHexFlag []byte
BytesHex exposes bytes as a flag, hex-encoded, optional whitespace padding, case insensitive, and optional 0x prefix.
func (*BytesHexFlag) Set ¶ added in v0.0.2
func (f *BytesHexFlag) Set(value string) error
func (BytesHexFlag) String ¶ added in v0.0.2
func (f BytesHexFlag) String() string
func (*BytesHexFlag) Type ¶ added in v0.0.2
func (f *BytesHexFlag) Type() string
type ChangedMarkers ¶ added in v0.1.0
ChangedMarkers tracks which flags are changed.
type CommandDescription ¶
type CommandDescription struct { FlagGroup // Define a field as 'MySettingChanged bool `changed:"my-setting"`' to e.g. track '--my-setting' being changed. // The same flag may be tracked with multiple fields ChangedMarkers ChangedMarkers // Command to run, may be nil if nothing has to run Command // Sub-command routing, can create commands (or other sub-commands) to access, may be nil if no sub-commands CommandRoute }
An interface{} can be loaded as a command-description to execute it. See Load()
func Load ¶
func Load(val interface{}) (*CommandDescription, error)
Load takes a structure instance that defines a command through its type, and the default values by determining them from the actual type.
func LoadReflect ¶
func LoadReflect(val reflect.Value) (*CommandDescription, error)
LoadReflect is the same as Load, but directly using reflection to handle the value.
func (*CommandDescription) Execute ¶
func (descr *CommandDescription) Execute(ctx context.Context, opts *ExecutionOptions, args ...string) (final *CommandDescription, err error)
Execute runs the command, with given context and arguments. Commands may have routes to sub-commands, the final sub-command that actually runs is returned, and may be nil in case of an error.
A HelpErr is returned when help information was requested for the command (through `help`, `--help` or `-h`) A UnrecognizedErr is returned when a sub-command was expected but not found.
To add inputs/outputs such as STDOUT to a command, add the readers/writers as field in the command struct definition, and the command can pass them on to sub-commands. Similarly logging and other misc. data can be passed around. The execute parameters are kept minimal.
opts.OnDeprecated is called for each deprecated flag, and command execution exits immediately if this callback returns an error.
func (*CommandDescription) Load ¶
func (descr *CommandDescription) Load(val interface{}) error
Load adds more flags/args/meta to the command description. It recursively goes into the field if it's tagged with `ask:"."` (recurse depth-first). Embedded fields are handled as regular fields unless explicitly squashed. It skips the field explicitly if it's tagged with `ask:"-"` Multiple target values can be loaded if they do not conflict, the first Command and CommandRoute found will be used. The flags will be set over all loaded values.
func (*CommandDescription) LoadReflect ¶
func (descr *CommandDescription) LoadReflect(val reflect.Value) error
LoadReflect is the same as Load, but directly using reflection to handle the value.
func (*CommandDescription) Usage ¶
func (descr *CommandDescription) Usage(showHidden bool) string
Usage prints the help information and the usage of all flags.
type CommandKnownRoutes ¶ added in v0.0.2
type CommandKnownRoutes interface { // Routes lists the sub-commands that can be asked from Get. Routes() []string }
CommandKnownRoutes may be implemented by a CommandRoute to declare which routes are accessible, useful for e.g. help messages to give more information for each of the subcommands.
type CommandRoute ¶
type CommandRoute interface { // Cmd gets a sub-command, which can be a Command or CommandRoute // The command that is returned will be loaded with `Load` before it runs or its subcommand is retrieved. // Return nil if the command route should be ignored, e.g. if this route is also a regular command with arguments. Cmd(route string) (cmd interface{}, err error) }
type DurationSliceValue ¶ added in v0.1.0
func (*DurationSliceValue) Set ¶ added in v0.1.0
func (s *DurationSliceValue) Set(val string) error
func (*DurationSliceValue) String ¶ added in v0.1.0
func (s *DurationSliceValue) String() string
func (*DurationSliceValue) Type ¶ added in v0.1.0
func (s *DurationSliceValue) Type() string
type DurationValue ¶ added in v0.1.0
func (*DurationValue) Set ¶ added in v0.1.0
func (d *DurationValue) Set(s string) error
func (*DurationValue) String ¶ added in v0.1.0
func (d *DurationValue) String() string
func (*DurationValue) Type ¶ added in v0.1.0
func (d *DurationValue) Type() string
type ExecutionOptions ¶ added in v0.1.0
type ExecutionOptions struct {
OnDeprecated func(fl PrefixedFlag) error
}
type Flag ¶ added in v0.1.0
type FlagGroup ¶ added in v0.1.0
type FlagGroup struct { GroupName string // Optional help info, provided by the struct that covers this group of flags Help // sub-groups Entries []*FlagGroup // flags in this group (does not include sub-groups) Flags []*Flag }
func (*FlagGroup) All ¶ added in v0.1.0
func (g *FlagGroup) All(prefix string) []PrefixedFlag
type Float32SliceValue ¶ added in v0.1.0
type Float32SliceValue []float32
func (*Float32SliceValue) Set ¶ added in v0.1.0
func (s *Float32SliceValue) Set(val string) error
func (*Float32SliceValue) String ¶ added in v0.1.0
func (s *Float32SliceValue) String() string
func (*Float32SliceValue) Type ¶ added in v0.1.0
func (s *Float32SliceValue) Type() string
type Float32Value ¶ added in v0.1.0
type Float32Value float32
func (*Float32Value) Set ¶ added in v0.1.0
func (f *Float32Value) Set(s string) error
func (*Float32Value) String ¶ added in v0.1.0
func (f *Float32Value) String() string
func (*Float32Value) Type ¶ added in v0.1.0
func (f *Float32Value) Type() string
type Float64SliceValue ¶ added in v0.1.0
type Float64SliceValue []float64
func (*Float64SliceValue) Set ¶ added in v0.1.0
func (s *Float64SliceValue) Set(val string) error
func (*Float64SliceValue) String ¶ added in v0.1.0
func (s *Float64SliceValue) String() string
func (*Float64SliceValue) Type ¶ added in v0.1.0
func (s *Float64SliceValue) Type() string
type Float64Value ¶ added in v0.1.0
type Float64Value float64
func (*Float64Value) Set ¶ added in v0.1.0
func (f *Float64Value) Set(s string) error
func (*Float64Value) String ¶ added in v0.1.0
func (f *Float64Value) String() string
func (*Float64Value) Type ¶ added in v0.1.0
func (f *Float64Value) Type() string
type Help ¶
type Help interface { // Help explains how a command or group of flags is used. Help() string }
type IPMaskValue ¶ added in v0.1.0
func (*IPMaskValue) Set ¶ added in v0.1.0
func (i *IPMaskValue) Set(s string) error
func (*IPMaskValue) String ¶ added in v0.1.0
func (i *IPMaskValue) String() string
func (*IPMaskValue) Type ¶ added in v0.1.0
func (i *IPMaskValue) Type() string
type IPNetValue ¶ added in v0.1.0
func (*IPNetValue) Set ¶ added in v0.1.0
func (ipnet *IPNetValue) Set(s string) error
func (IPNetValue) String ¶ added in v0.1.0
func (ipnet IPNetValue) String() string
func (*IPNetValue) Type ¶ added in v0.1.0
func (*IPNetValue) Type() string
type IPSliceValue ¶ added in v0.1.0
func (*IPSliceValue) Set ¶ added in v0.1.0
func (s *IPSliceValue) Set(val string) error
func (*IPSliceValue) String ¶ added in v0.1.0
func (s *IPSliceValue) String() string
func (*IPSliceValue) Type ¶ added in v0.1.0
func (s *IPSliceValue) Type() string
type ImplicitValue ¶ added in v0.1.0
type InitDefault ¶ added in v0.0.2
type InitDefault interface {
// Default the flags of a command.
Default()
}
InitDefault can be implemented by a command to not rely on the parent command initializing the command correctly, and instead move the responsibility to the command itself. The default is initialized during Load, and a command may embed multiple sub-structures that implement Default.
type InlineHelp ¶ added in v0.1.0
type InlineHelp string
func (InlineHelp) Help ¶ added in v0.1.0
func (v InlineHelp) Help() string
type Int16SliceValue ¶ added in v0.1.0
type Int16SliceValue []int16
func (*Int16SliceValue) Set ¶ added in v0.1.0
func (s *Int16SliceValue) Set(val string) error
func (*Int16SliceValue) String ¶ added in v0.1.0
func (s *Int16SliceValue) String() string
func (*Int16SliceValue) Type ¶ added in v0.1.0
func (s *Int16SliceValue) Type() string
type Int16Value ¶ added in v0.1.0
type Int16Value int16
func (*Int16Value) Set ¶ added in v0.1.0
func (i *Int16Value) Set(s string) error
func (*Int16Value) String ¶ added in v0.1.0
func (i *Int16Value) String() string
func (*Int16Value) Type ¶ added in v0.1.0
func (i *Int16Value) Type() string
type Int32SliceValue ¶ added in v0.1.0
type Int32SliceValue []int32
func (*Int32SliceValue) Set ¶ added in v0.1.0
func (s *Int32SliceValue) Set(val string) error
func (*Int32SliceValue) String ¶ added in v0.1.0
func (s *Int32SliceValue) String() string
func (*Int32SliceValue) Type ¶ added in v0.1.0
func (s *Int32SliceValue) Type() string
type Int32Value ¶ added in v0.1.0
type Int32Value int32
func (*Int32Value) Set ¶ added in v0.1.0
func (i *Int32Value) Set(s string) error
func (*Int32Value) String ¶ added in v0.1.0
func (i *Int32Value) String() string
func (*Int32Value) Type ¶ added in v0.1.0
func (i *Int32Value) Type() string
type Int64SliceValue ¶ added in v0.1.0
type Int64SliceValue []int64
func (*Int64SliceValue) Set ¶ added in v0.1.0
func (s *Int64SliceValue) Set(val string) error
func (*Int64SliceValue) String ¶ added in v0.1.0
func (s *Int64SliceValue) String() string
func (*Int64SliceValue) Type ¶ added in v0.1.0
func (s *Int64SliceValue) Type() string
type Int64Value ¶ added in v0.1.0
type Int64Value int64
func (*Int64Value) Set ¶ added in v0.1.0
func (i *Int64Value) Set(s string) error
func (*Int64Value) String ¶ added in v0.1.0
func (i *Int64Value) String() string
func (*Int64Value) Type ¶ added in v0.1.0
func (i *Int64Value) Type() string
type Int8SliceValue ¶ added in v0.1.0
type Int8SliceValue []int8
func (*Int8SliceValue) Set ¶ added in v0.1.0
func (s *Int8SliceValue) Set(val string) error
func (*Int8SliceValue) String ¶ added in v0.1.0
func (s *Int8SliceValue) String() string
func (*Int8SliceValue) Type ¶ added in v0.1.0
func (s *Int8SliceValue) Type() string
type IntSliceValue ¶ added in v0.1.0
type IntSliceValue []int
func (*IntSliceValue) Set ¶ added in v0.1.0
func (s *IntSliceValue) Set(val string) error
func (*IntSliceValue) String ¶ added in v0.1.0
func (s *IntSliceValue) String() string
func (*IntSliceValue) Type ¶ added in v0.1.0
func (s *IntSliceValue) Type() string
type PrefixedFlag ¶ added in v0.1.0
type StringSliceValue ¶ added in v0.1.0
type StringSliceValue []string
func (*StringSliceValue) Set ¶ added in v0.1.0
func (s *StringSliceValue) Set(val string) error
func (*StringSliceValue) String ¶ added in v0.1.0
func (s *StringSliceValue) String() string
func (*StringSliceValue) Type ¶ added in v0.1.0
func (s *StringSliceValue) Type() string
type StringValue ¶ added in v0.1.0
type StringValue string
func (*StringValue) Set ¶ added in v0.1.0
func (s *StringValue) Set(val string) error
func (*StringValue) String ¶ added in v0.1.0
func (s *StringValue) String() string
func (*StringValue) Type ¶ added in v0.1.0
func (s *StringValue) Type() string
type TypedValue ¶ added in v0.1.0
TypedValue is the interface to the dynamic value stored in a flag. (The default value is represented as a string.) Extension of flag.Value with Type information.
type Uint16SliceValue ¶ added in v0.1.0
type Uint16SliceValue []uint16
func (*Uint16SliceValue) Set ¶ added in v0.1.0
func (s *Uint16SliceValue) Set(val string) error
func (*Uint16SliceValue) String ¶ added in v0.1.0
func (s *Uint16SliceValue) String() string
func (*Uint16SliceValue) Type ¶ added in v0.1.0
func (s *Uint16SliceValue) Type() string
type Uint16Value ¶ added in v0.1.0
type Uint16Value uint16
func (*Uint16Value) Set ¶ added in v0.1.0
func (i *Uint16Value) Set(s string) error
func (*Uint16Value) String ¶ added in v0.1.0
func (i *Uint16Value) String() string
func (*Uint16Value) Type ¶ added in v0.1.0
func (i *Uint16Value) Type() string
type Uint32SliceValue ¶ added in v0.1.0
type Uint32SliceValue []uint32
func (*Uint32SliceValue) Set ¶ added in v0.1.0
func (s *Uint32SliceValue) Set(val string) error
func (*Uint32SliceValue) String ¶ added in v0.1.0
func (s *Uint32SliceValue) String() string
func (*Uint32SliceValue) Type ¶ added in v0.1.0
func (s *Uint32SliceValue) Type() string
type Uint32Value ¶ added in v0.1.0
type Uint32Value uint32
func (*Uint32Value) Set ¶ added in v0.1.0
func (i *Uint32Value) Set(s string) error
func (*Uint32Value) String ¶ added in v0.1.0
func (i *Uint32Value) String() string
func (*Uint32Value) Type ¶ added in v0.1.0
func (i *Uint32Value) Type() string
type Uint64SliceValue ¶ added in v0.1.0
type Uint64SliceValue []uint64
func (*Uint64SliceValue) Set ¶ added in v0.1.0
func (s *Uint64SliceValue) Set(val string) error
func (*Uint64SliceValue) String ¶ added in v0.1.0
func (s *Uint64SliceValue) String() string
func (*Uint64SliceValue) Type ¶ added in v0.1.0
func (s *Uint64SliceValue) Type() string
type Uint64Value ¶ added in v0.1.0
type Uint64Value uint64
func (*Uint64Value) Set ¶ added in v0.1.0
func (i *Uint64Value) Set(s string) error
func (*Uint64Value) String ¶ added in v0.1.0
func (i *Uint64Value) String() string
func (*Uint64Value) Type ¶ added in v0.1.0
func (i *Uint64Value) Type() string
type Uint8Value ¶ added in v0.1.0
type Uint8Value uint8
func (*Uint8Value) Set ¶ added in v0.1.0
func (i *Uint8Value) Set(s string) error
func (*Uint8Value) String ¶ added in v0.1.0
func (i *Uint8Value) String() string
func (*Uint8Value) Type ¶ added in v0.1.0
func (i *Uint8Value) Type() string
type UintSliceValue ¶ added in v0.1.0
type UintSliceValue []uint
func (*UintSliceValue) Set ¶ added in v0.1.0
func (s *UintSliceValue) Set(val string) error
func (*UintSliceValue) String ¶ added in v0.1.0
func (s *UintSliceValue) String() string
func (*UintSliceValue) Type ¶ added in v0.1.0
func (s *UintSliceValue) Type() string