Documentation ¶
Overview ¶
Package clipper processes the command-line arguments of getopt(3) syntax. This package provides the ability to process the root command, sub commands, command-line arguments and command-line flags.
Index ¶
- Variables
- func CheckLen(name string, length, min, max int) error
- func PrintHelp(registry *Registry, commandName string, commandConfig *CommandConfig, ...)
- func SplitQuoted(s string) []string
- func WrapInvalidValue(prefix string, err error) error
- type Arg
- type CommandConfig
- func (commandConfig *CommandConfig) AddBool(name, shortName string, value bool, b *bool, help string) *Opt
- func (commandConfig *CommandConfig) AddBoolArray(name, shortName string, value []bool, p *[]bool, help string) *Opt
- func (commandConfig *CommandConfig) AddBoolArrayFromCSV(name, shortName string, value string, p *[]bool, help string) *Opt
- func (commandConfig *CommandConfig) AddBoolFromString(name, shortName string, value string, b *bool, help string) *Opt
- func (commandConfig *CommandConfig) AddCounterFlag(name, shortName string, c *int, help string) *Opt
- func (commandConfig *CommandConfig) AddDuration(name, shortName string, value time.Duration, p *time.Duration, help string) *Opt
- func (commandConfig *CommandConfig) AddFlag(name, shortName string, b *bool, help string) *Opt
- func (commandConfig *CommandConfig) AddFloat32(name, shortName string, value float32, p *float32, help string) *Opt
- func (commandConfig *CommandConfig) AddFloat64(name, shortName string, value float64, p *float64, help string) *Opt
- func (commandConfig *CommandConfig) AddIP(name, shortName string, value net.IP, p *net.IP, help string) *Opt
- func (commandConfig *CommandConfig) AddIPArray(name, shortName string, value []net.IP, p *[]net.IP, help string) *Opt
- func (commandConfig *CommandConfig) AddIPArrayFromCSV(name, shortName string, value string, p *[]net.IP, help string) *Opt
- func (commandConfig *CommandConfig) AddIPFromString(name, shortName string, value string, p *net.IP, help string) *Opt
- func (commandConfig *CommandConfig) AddInt(name, shortName string, value int, p *int, help string) *Opt
- func (commandConfig *CommandConfig) AddInt16(name, shortName string, value int16, p *int16, help string) *Opt
- func (commandConfig *CommandConfig) AddInt32(name, shortName string, value int32, p *int32, help string) *Opt
- func (commandConfig *CommandConfig) AddInt32Array(name, shortName string, value []int32, p *[]int32, help string) *Opt
- func (commandConfig *CommandConfig) AddInt32ArrayFromCSV(name, shortName string, value string, p *[]int32, help string) *Opt
- func (commandConfig *CommandConfig) AddInt64(name, shortName string, value int64, p *int64, help string) *Opt
- func (commandConfig *CommandConfig) AddInt64Array(name, shortName string, value []int64, p *[]int64, help string) *Opt
- func (commandConfig *CommandConfig) AddInt64ArrayFromCSV(name, shortName string, value string, p *[]int64, help string) *Opt
- func (commandConfig *CommandConfig) AddInt64N(name, shortName string, value int64, p *int64, help string) *Opt
- func (commandConfig *CommandConfig) AddInt64NArray(name, shortName string, value []int64, p *[]int64, help string) *Opt
- func (commandConfig *CommandConfig) AddInt64NFromString(name, shortName string, value string, p *int64, help string) *Opt
- func (commandConfig *CommandConfig) AddInt8(name, shortName string, value int8, p *int8, help string) *Opt
- func (commandConfig *CommandConfig) AddInt8Array(name, shortName string, value []int8, p *[]int8, help string) *Opt
- func (commandConfig *CommandConfig) AddInt8ArrayFromCSV(name, shortName string, value string, p *[]int8, help string) *Opt
- func (commandConfig *CommandConfig) AddIntArray(name, shortName string, value []int, p *[]int, help string) *Opt
- func (commandConfig *CommandConfig) AddIntArrayFromCSV(name, shortName string, value string, p *[]int, help string) *Opt
- func (commandConfig *CommandConfig) AddMultiFlag(name, shortName string, b *[]bool, help string) *Opt
- func (commandConfig *CommandConfig) AddString(name, shortName string, value string, p *string, help string) *Opt
- func (commandConfig *CommandConfig) AddStringArgs(max int, p *[]string, help string) Arg
- func (commandConfig *CommandConfig) AddStringArray(name, shortName string, value []string, p *[]string, help string) *Opt
- func (commandConfig *CommandConfig) AddStringArrayFromCSV(name, shortName string, value string, p *[]string, help string) *Opt
- func (commandConfig *CommandConfig) AddTime(name, shortName string, value time.Time, p *time.Time, layout string, ...) *Opt
- func (commandConfig *CommandConfig) AddTimeFromString(name, shortName string, value string, p *time.Time, layout string, help string) *Opt
- func (commandConfig *CommandConfig) AddUint(name, shortName string, value uint, p *uint, help string) *Opt
- func (commandConfig *CommandConfig) AddUint16(name, shortName string, value uint16, p *uint16, help string) *Opt
- func (commandConfig *CommandConfig) AddUint16Array(name, shortName string, value []uint16, p *[]uint16, help string) *Opt
- func (commandConfig *CommandConfig) AddUint16ArrayFromCSV(name, shortName string, value string, p *[]uint16, help string) *Opt
- func (commandConfig *CommandConfig) AddUint32(name, shortName string, value uint32, p *uint32, help string) *Opt
- func (commandConfig *CommandConfig) AddUint32Array(name, shortName string, value []uint32, p *[]uint32, help string) *Opt
- func (commandConfig *CommandConfig) AddUint32ArrayFromCSV(name, shortName string, value string, p *[]uint32, help string) *Opt
- func (commandConfig *CommandConfig) AddUint64(name, shortName string, value uint64, p *uint64, help string) *Opt
- func (commandConfig *CommandConfig) AddUint64Array(name, shortName string, value []uint64, p *[]uint64, help string) *Opt
- func (commandConfig *CommandConfig) AddUint64ArrayFromCSV(name, shortName string, value string, p *[]uint64, help string) *Opt
- func (commandConfig *CommandConfig) AddUint64N(name, shortName string, value uint64, p *uint64, help string) *Opt
- func (commandConfig *CommandConfig) AddUint64NArray(name, shortName string, value []uint64, p *[]uint64, help string) *Opt
- func (commandConfig *CommandConfig) AddUint64NArrayFromCSV(name, shortName string, value string, p *[]uint64, help string) *Opt
- func (commandConfig *CommandConfig) AddUint64NFromString(name, shortName string, value string, p *uint64, help string) *Opt
- func (commandConfig *CommandConfig) AddUint8(name, shortName string, value uint8, p *uint8, help string) *Opt
- func (commandConfig *CommandConfig) AddUint8Array(name, shortName string, value []uint8, p *[]uint8, help string) *Opt
- func (commandConfig *CommandConfig) AddUint8ArrayFromCSV(name, shortName string, value string, p *[]uint8, help string) *Opt
- func (commandConfig *CommandConfig) AddUintArray(name, shortName string, value []uint, p *[]uint, help string) *Opt
- func (commandConfig *CommandConfig) AddUintArrayFromCSV(name, shortName string, value string, p *[]uint, help string) *Opt
- func (commandConfig *CommandConfig) AddValue(name, shortName string, v Value, isMultiValue bool, help string) *Opt
- func (commandConfig *CommandConfig) AddVersionHelper(name, shortName, description, version string)
- func (commandConfig *CommandConfig) Addint16Array(name, shortName string, value []int16, p *[]int16, help string) *Opt
- func (commandConfig *CommandConfig) Addint16ArrayFromCSV(name, shortName string, value string, p *[]int16, help string) *Opt
- func (commandConfig *CommandConfig) Addint64NArrayFromCSV(name, shortName string, value string, p *[]int64, help string) *Opt
- func (commandConfig *CommandConfig) DisableArgs() Arg
- func (commandConfig *CommandConfig) GetFlag(flag string) *Opt
- func (commandConfig *CommandConfig) Reset()
- type ErrorInvalidValue
- type ErrorLengthOverflow
- type ErrorRequiredFlag
- type ErrorUnknownCommand
- type ErrorUnknownFlag
- type ErrorUnsupportedFlag
- type ErrorUnsupportedValue
- type None
- func (None) CheckLen() error
- func (None) Get() interface{}
- func (None) MaxLen() int
- func (None) MinLen() int
- func (None) Reset(interface{})
- func (None) Set(v string, _ bool) error
- func (n None) SetMaxLen(_ int) Arg
- func (n None) SetMinLen(_ int) Arg
- func (None) String() string
- func (None) Type() string
- type Opt
- func (o *Opt) AttachEnv(envName string) *Opt
- func (o *Opt) GetCompeterValue() string
- func (o *Opt) Reset()
- func (o *Opt) Set(s string) error
- func (o *Opt) SetCompeterValue(competerValue string) *Opt
- func (o *Opt) SetRequired(required bool) *Opt
- func (o *Opt) SetUsage(usage string) *Opt
- func (o *Opt) SetValidValues(validValues []string) *Opt
- func (o *Opt) Validate(s string) (isValid bool)
- type Registry
- func (registry *Registry) Completer(line string) (c []string)
- func (registry *Registry) Parse(values []string) (commandName string, err error)
- func (registry *Registry) ParseInteract(values []string, dryRun bool) (commandName string, helpExit bool, err error)
- func (registry *Registry) ParseOpt(values []string, exitOnHelp bool, dryRun bool) (commandName string, helpExit bool, err error)
- func (registry *Registry) Register(name string, help string) (*CommandConfig, bool)
- func (registry *Registry) RegisterHelp(name string, help string, printCmdName, exitOnHelp bool)
- func (registry *Registry) RegisterWithCallback(name string, help string, callback func() error) (*CommandConfig, bool)
- func (registry *Registry) Reset()
- func (registry *Registry) ResetCommand(commandName string)
- type Value
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func PrintHelp ¶
func PrintHelp(registry *Registry, commandName string, commandConfig *CommandConfig, printCmdName bool)
func SplitQuoted ¶ added in v0.0.7
func WrapInvalidValue ¶
Types ¶
type CommandConfig ¶
type CommandConfig struct { // name of the sub-command ("" for the root command) Name string Help string // help message for command // named command-line options order (for display help) OptsOrder []string // named command-line options or boolean flags Opts map[string]*Opt // Unnamed args Args Arg // help message for command unnamed arguments ArgsHelp string Callback func() error // contains filtered or unexported fields }
CommandConfig type holds the structure and values of the command-line arguments of command.
func (*CommandConfig) AddBool ¶
func (commandConfig *CommandConfig) AddBool(name, shortName string, value bool, b *bool, help string) *Opt
AddBool registers an bool configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddBoolArray ¶
func (commandConfig *CommandConfig) AddBoolArray(name, shortName string, value []bool, p *[]bool, help string) *Opt
AddBoolArray registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddBoolArrayFromCSV ¶
func (commandConfig *CommandConfig) AddBoolArrayFromCSV(name, shortName string, value string, p *[]bool, help string) *Opt
AddBoolArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddBoolFromString ¶ added in v0.0.15
func (commandConfig *CommandConfig) AddBoolFromString(name, shortName string, value string, b *bool, help string) *Opt
AddBoolFromString registers an bool configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddCounterFlag ¶ added in v0.0.24
func (commandConfig *CommandConfig) AddCounterFlag(name, shortName string, c *int, help string) *Opt
AddCounterFlag registers an counter (direct) multi-flag with the command (for cases like -vvv). The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddDuration ¶
func (commandConfig *CommandConfig) AddDuration(name, shortName string, value time.Duration, p *time.Duration, help string) *Opt
AddDuration registers an duration argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddFlag ¶
func (commandConfig *CommandConfig) AddFlag(name, shortName string, b *bool, help string) *Opt
AddFlag registers an bool (direct/inverted) flag with the command. The `name` argument represents the name of the argument. If value of the `name` argument starts with `no-` prefix, then it is a inverted flag. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddFloat32 ¶
func (commandConfig *CommandConfig) AddFloat32(name, shortName string, value float32, p *float32, help string) *Opt
AddFloat32 registers an float32 argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddFloat64 ¶
func (commandConfig *CommandConfig) AddFloat64(name, shortName string, value float64, p *float64, help string) *Opt
AddFloat64 registers an float64 argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddIP ¶
func (commandConfig *CommandConfig) AddIP(name, shortName string, value net.IP, p *net.IP, help string) *Opt
AddIP registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddIPArray ¶
func (commandConfig *CommandConfig) AddIPArray(name, shortName string, value []net.IP, p *[]net.IP, help string) *Opt
AddIPArray registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddIPArrayFromCSV ¶
func (commandConfig *CommandConfig) AddIPArrayFromCSV(name, shortName string, value string, p *[]net.IP, help string) *Opt
Addnet.IPArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddIPFromString ¶
func (commandConfig *CommandConfig) AddIPFromString(name, shortName string, value string, p *net.IP, help string) *Opt
AddIPFromString registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt ¶
func (commandConfig *CommandConfig) AddInt(name, shortName string, value int, p *int, help string) *Opt
AddInt registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt16 ¶
func (commandConfig *CommandConfig) AddInt16(name, shortName string, value int16, p *int16, help string) *Opt
AddInt16 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt32 ¶
func (commandConfig *CommandConfig) AddInt32(name, shortName string, value int32, p *int32, help string) *Opt
AddInt32 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt32Array ¶
func (commandConfig *CommandConfig) AddInt32Array(name, shortName string, value []int32, p *[]int32, help string) *Opt
AddInt32Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt32ArrayFromCSV ¶
func (commandConfig *CommandConfig) AddInt32ArrayFromCSV(name, shortName string, value string, p *[]int32, help string) *Opt
AddInt32ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt64 ¶
func (commandConfig *CommandConfig) AddInt64(name, shortName string, value int64, p *int64, help string) *Opt
AddInt64 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt64Array ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddInt64Array(name, shortName string, value []int64, p *[]int64, help string) *Opt
AddInt64Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt64ArrayFromCSV ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddInt64ArrayFromCSV(name, shortName string, value string, p *[]int64, help string) *Opt
AddInt64ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt64N ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddInt64N(name, shortName string, value int64, p *int64, help string) *Opt
AddInt64 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt64NArray ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddInt64NArray(name, shortName string, value []int64, p *[]int64, help string) *Opt
AddInt64Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt64NFromString ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddInt64NFromString(name, shortName string, value string, p *int64, help string) *Opt
AddInt64N registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. The `value` argument represents initial value, with suffix of k (1e3), m (1e6), g (1e9), K (1024), M (1048576), G (1073741824) If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt8 ¶
func (commandConfig *CommandConfig) AddInt8(name, shortName string, value int8, p *int8, help string) *Opt
AddInt8 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt8Array ¶
func (commandConfig *CommandConfig) AddInt8Array(name, shortName string, value []int8, p *[]int8, help string) *Opt
AddInt8Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddInt8ArrayFromCSV ¶
func (commandConfig *CommandConfig) AddInt8ArrayFromCSV(name, shortName string, value string, p *[]int8, help string) *Opt
AddInt8ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddIntArray ¶
func (commandConfig *CommandConfig) AddIntArray(name, shortName string, value []int, p *[]int, help string) *Opt
AddIntArray registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddIntArrayFromCSV ¶
func (commandConfig *CommandConfig) AddIntArrayFromCSV(name, shortName string, value string, p *[]int, help string) *Opt
AddIntArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddMultiFlag ¶
func (commandConfig *CommandConfig) AddMultiFlag(name, shortName string, b *[]bool, help string) *Opt
AddMultiFlag registers an bool (direct/inverted) multi-flag with the command (for cases like -vvv). The `name` argument represents the name of the argument. If value of the `name` argument starts with `no-` prefix, then it is a inverted flag. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddString ¶
func (commandConfig *CommandConfig) AddString(name, shortName string, value string, p *string, help string) *Opt
AddString registers an string argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddStringArgs ¶
func (commandConfig *CommandConfig) AddStringArgs(max int, p *[]string, help string) Arg
AddStringArgs set unnamed argument configuration with the command. The `max` argument represents maximum length of unnamed args (-1 - unlimited). `Arg` object returned.
func (*CommandConfig) AddStringArray ¶
func (commandConfig *CommandConfig) AddStringArray(name, shortName string, value []string, p *[]string, help string) *Opt
AddStringArray registers an string argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddStringArrayFromCSV ¶
func (commandConfig *CommandConfig) AddStringArrayFromCSV(name, shortName string, value string, p *[]string, help string) *Opt
AddStringArrayFromCSV registers an string argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddTime ¶
func (commandConfig *CommandConfig) AddTime(name, shortName string, value time.Time, p *time.Time, layout string, help string) *Opt
AddTime registers an duration argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddTimeFromString ¶ added in v0.0.4
func (commandConfig *CommandConfig) AddTimeFromString(name, shortName string, value string, p *time.Time, layout string, help string) *Opt
AddTimeFromString registers an duration argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint ¶
func (commandConfig *CommandConfig) AddUint(name, shortName string, value uint, p *uint, help string) *Opt
AddUint registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint16 ¶
func (commandConfig *CommandConfig) AddUint16(name, shortName string, value uint16, p *uint16, help string) *Opt
AddUint16 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint16Array ¶
func (commandConfig *CommandConfig) AddUint16Array(name, shortName string, value []uint16, p *[]uint16, help string) *Opt
AddUint16Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint16ArrayFromCSV ¶
func (commandConfig *CommandConfig) AddUint16ArrayFromCSV(name, shortName string, value string, p *[]uint16, help string) *Opt
AddUint16ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint32 ¶
func (commandConfig *CommandConfig) AddUint32(name, shortName string, value uint32, p *uint32, help string) *Opt
AddUint32 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint32Array ¶
func (commandConfig *CommandConfig) AddUint32Array(name, shortName string, value []uint32, p *[]uint32, help string) *Opt
AddUint32Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint32ArrayFromCSV ¶
func (commandConfig *CommandConfig) AddUint32ArrayFromCSV(name, shortName string, value string, p *[]uint32, help string) *Opt
AddUint32ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint64 ¶
func (commandConfig *CommandConfig) AddUint64(name, shortName string, value uint64, p *uint64, help string) *Opt
AddUint64 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint64Array ¶
func (commandConfig *CommandConfig) AddUint64Array(name, shortName string, value []uint64, p *[]uint64, help string) *Opt
AddUint64Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint64ArrayFromCSV ¶
func (commandConfig *CommandConfig) AddUint64ArrayFromCSV(name, shortName string, value string, p *[]uint64, help string) *Opt
AddUint64ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint64N ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddUint64N(name, shortName string, value uint64, p *uint64, help string) *Opt
AddUint64N registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint64NArray ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddUint64NArray(name, shortName string, value []uint64, p *[]uint64, help string) *Opt
AddUint64NArray registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint64NArrayFromCSV ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddUint64NArrayFromCSV(name, shortName string, value string, p *[]uint64, help string) *Opt
AddUint64ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint64NFromString ¶ added in v0.0.21
func (commandConfig *CommandConfig) AddUint64NFromString(name, shortName string, value string, p *uint64, help string) *Opt
AddUint64N registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. The `value` argument represents initial value, with suffix of k (1e3), m (1e6), g (1e9), K (1024), M (1048576), G (1073741824) If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint8 ¶
func (commandConfig *CommandConfig) AddUint8(name, shortName string, value uint8, p *uint8, help string) *Opt
AddUint8 registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint8Array ¶
func (commandConfig *CommandConfig) AddUint8Array(name, shortName string, value []uint8, p *[]uint8, help string) *Opt
AddUint8Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUint8ArrayFromCSV ¶
func (commandConfig *CommandConfig) AddUint8ArrayFromCSV(name, shortName string, value string, p *[]uint8, help string) *Opt
AddUint8ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUintArray ¶
func (commandConfig *CommandConfig) AddUintArray(name, shortName string, value []uint, p *[]uint, help string) *Opt
AddintArray registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddUintArrayFromCSV ¶
func (commandConfig *CommandConfig) AddUintArrayFromCSV(name, shortName string, value string, p *[]uint, help string) *Opt
AddintArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddValue ¶
func (commandConfig *CommandConfig) AddValue(name, shortName string, v Value, isMultiValue bool, help string) *Opt
AddValue registers an argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) AddVersionHelper ¶
func (commandConfig *CommandConfig) AddVersionHelper(name, shortName, description, version string)
AddVersion method registers a version callback.
func (*CommandConfig) Addint16Array ¶
func (commandConfig *CommandConfig) Addint16Array(name, shortName string, value []int16, p *[]int16, help string) *Opt
AddInt16Array registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) Addint16ArrayFromCSV ¶
func (commandConfig *CommandConfig) Addint16ArrayFromCSV(name, shortName string, value string, p *[]int16, help string) *Opt
AddInt16ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) Addint64NArrayFromCSV ¶ added in v0.0.21
func (commandConfig *CommandConfig) Addint64NArrayFromCSV(name, shortName string, value string, p *[]int64, help string) *Opt
AddInt64ArrayFromCSV registers an int argument configuration with the command. The `name` argument represents the name of the argument. The `shortName` argument represents the short alias of the argument. If an argument with given `name` is already registered, then panic registered `*Opt` object returned.
func (*CommandConfig) DisableArgs ¶
func (commandConfig *CommandConfig) DisableArgs() Arg
DisableArgs disable unnamed argument configuration with the command. registered `*Opt` object returned.
func (*CommandConfig) GetFlag ¶ added in v0.0.15
func (commandConfig *CommandConfig) GetFlag(flag string) *Opt
Reset method reset values to it's default values.
func (*CommandConfig) Reset ¶ added in v0.0.11
func (commandConfig *CommandConfig) Reset()
Reset method reset values to it's default values.
type ErrorInvalidValue ¶
type ErrorInvalidValue struct { Prefix string // contains filtered or unexported fields }
ErrorWrapped represents an wrapped error
func (ErrorInvalidValue) Error ¶
func (e ErrorInvalidValue) Error() string
type ErrorLengthOverflow ¶
ErrorUnsupportedValue represents an error when command-line arguments contain an unsupported value.
func (ErrorLengthOverflow) Error ¶
func (e ErrorLengthOverflow) Error() string
type ErrorRequiredFlag ¶
type ErrorRequiredFlag struct {
Name string
}
ErrorRequiredFlag represents an error when command-line arguments not contain an required flag.
func (ErrorRequiredFlag) Error ¶
func (e ErrorRequiredFlag) Error() string
type ErrorUnknownCommand ¶
type ErrorUnknownCommand struct {
Name string
}
ErrorUnknownCommand represents an error when command-line arguments contain an unregistered command.
func (ErrorUnknownCommand) Error ¶
func (e ErrorUnknownCommand) Error() string
type ErrorUnknownFlag ¶
type ErrorUnknownFlag struct {
Name string
}
ErrorUnknownFlag represents an error when command-line arguments contain an unregistered flag.
func (ErrorUnknownFlag) Error ¶
func (e ErrorUnknownFlag) Error() string
type ErrorUnsupportedFlag ¶
type ErrorUnsupportedFlag struct {
Name string
}
ErrorUnsupportedFlag represents an error when command-line arguments contain an unsupported flag.
func (ErrorUnsupportedFlag) Error ¶
func (e ErrorUnsupportedFlag) Error() string
type ErrorUnsupportedValue ¶
ErrorUnsupportedValue represents an error when command-line arguments contain an unsupported value.
func (ErrorUnsupportedValue) Error ¶
func (e ErrorUnsupportedValue) Error() string
type None ¶
type None struct{}
None is disabled value (can't set). (The default value is represented as a string.)
type Opt ¶
type Opt struct { Name string // long name of the flag ShortName string // short name of the flag EnvName string // OS environment variable name Help string // help message CompleterValue string // help for completer value (may be format, by default value type) IsMultiValue bool // helper for completer IsFlag bool // boolean flag (direct/inverted) IsInverted bool // inverted boolean flag // IsVariadic bool // true if can take multiple values IsRequired bool // required value ValidValues map[string]bool // valid values Changed bool // if the user set the value (or if left to default) Value Value // value as set // contains filtered or unexported fields }
Opt type holds the structured information about a flag.
func (*Opt) AttachEnv ¶ added in v0.0.16
AttachEnv set OS environment name, which used for set variable before parse other args `*Opt` object returned.
func (*Opt) GetCompeterValue ¶ added in v0.0.15
GetCompeterValue return comleter value
func (*Opt) Set ¶
Set set Use with valid backend Value (may be slice) or values can be lost/corrupted `*Opt` object returned.
func (*Opt) SetCompeterValue ¶ added in v0.0.15
SetCompeterValue return comleter value `*Opt` object returned.
func (*Opt) SetRequired ¶
SetRequired enable/disable required `*Opt` object returned.
func (*Opt) SetValidValues ¶
SetValidValues set values for validate `*Opt` object returned.
type Registry ¶
type Registry struct { Commands map[string]*CommandConfig Description string // help message }
Registry holds the configuration of the registered commands.
func NewRegistry ¶
NewRegistry returns new instance of the "Registry"
func (*Registry) Completer ¶
Completer return slice of completer variants with prepended initial line
func (*Registry) Parse ¶
Parse method parses command-line arguments and returns an appropriate command name, registered in the registry. If -h or --help flag found, program will be exited with code 0. If command is not registered, it return `ErrorUnknownCommand` error. If there is an error parsing a flag, it can return an `ErrorUnknownFlag` or `ErrorUnsupportedFlag` error.
func (*Registry) ParseInteract ¶
func (registry *Registry) ParseInteract(values []string, dryRun bool) (commandName string, helpExit bool, err error)
ParseInteract method parses command-line arguments and returns an appropriate command name, registered in the registry. If -h or --help flag found, return helpExit with `true` value`. The `dryRun` argument set test mode (no value changed). If command is not registered, it return `ErrorUnknownCommand` error. If there is an error parsing a flag, it can return an `ErrorUnknownFlag` or `ErrorUnsupportedFlag` error.
func (*Registry) ParseOpt ¶
func (registry *Registry) ParseOpt(values []string, exitOnHelp bool, dryRun bool) (commandName string, helpExit bool, err error)
ParseOpt method parses command-line arguments and returns an appropriate command name, registered in the registry. The `helpExit` argument set interactive mode (if -h or --help flag found, return helpExit with `true` value`). The `dryRun` argument set test mode (no value changed). If command is not registered, it return `ErrorUnknownCommand` error. If there is an error parsing a flag, it can return an `ErrorUnknownFlag` or `ErrorUnsupportedFlag` error.
func (*Registry) Register ¶
func (registry *Registry) Register(name string, help string) (*CommandConfig, bool)
Register method registers a command. The "name" argument should be a simple string. If "name" is an empty string, it is considered as a root command. If a command is already registered, the registered `*CommandConfig` object is returned. If the command is already registered, second return value will be `true`.
func (*Registry) RegisterHelp ¶ added in v0.0.22
AddHelp method register a help command callback.
func (*Registry) RegisterWithCallback ¶ added in v0.0.22
func (registry *Registry) RegisterWithCallback(name string, help string, callback func() error) (*CommandConfig, bool)
RegisterWithCallback method registers a command. The "name" argument should be a simple string. If "name" is an empty string, it is considered as a root command. If a command is already registered, the registered `*CommandConfig` object is returned. If the command is already registered, second return value will be `true`.
func (*Registry) Reset ¶
func (registry *Registry) Reset()
Reset method reset all values to it's default values.
func (*Registry) ResetCommand ¶ added in v0.0.13
ResetCommand method reset values in command scope to it's default values.
Source Files ¶
- bool.go
- bool_array.go
- clipper.go
- completer.go
- counter.go
- duration.go
- errors.go
- float32.go
- float64.go
- help.go
- int.go
- int16.go
- int16_array.go
- int32.go
- int32_array.go
- int64.go
- int64_array.go
- int64n.go
- int64n_array.go
- int8.go
- int8_array.go
- int_array.go
- ip.go
- ip_array.go
- string.go
- string_array.go
- time.go
- uint.go
- uint16.go
- uint16_array.go
- uint32.go
- uint32_array.go
- uint64.go
- uint64_array.go
- uint64n.go
- uint64n_array.go
- uint8.go
- uint8_array.go
- uint_array.go
- value.go
- version.go