Documentation
¶
Index ¶
- func WithChoices[T interface{ ... }](opt T, choices ...string) T
- func WithDefault[T interface{ ... }](opt T, value string) T
- func WithMetavar[T interface{ ... }](opt T, metavar string) T
- func WithNargs[T interface{ ... }](opt T, nargs Nargs) T
- func WithOptionalArgument[T interface{ ... }](opt T, constValue string) T
- type BoolOption
- func (base *BoolOption) GetChoices() []string
- func (base *BoolOption) GetConst() string
- func (base *BoolOption) GetDefault() *string
- func (base *BoolOption) GetLongName() string
- func (base *BoolOption) GetMetavar() string
- func (base *BoolOption) GetNargs() Nargs
- func (base *BoolOption) GetRequired() bool
- func (base *BoolOption) GetShortName() string
- func (base *BoolOption) GetUsage() string
- func (boolOption *BoolOption) Set(_ string) error
- func (base *BoolOption) SetChoices(choices ...string)
- func (base *BoolOption) SetConst(value string)
- func (base *BoolOption) SetDefault(value string)
- func (base *BoolOption) SetMetavar(metavar string)
- func (base *BoolOption) SetNargs(nargs Nargs)
- type ChoiceNormalizer
- type ChoicesProvider
- type ConstProvider
- type CountedOption
- func (base *CountedOption) GetChoices() []string
- func (base *CountedOption) GetConst() string
- func (base *CountedOption) GetDefault() *string
- func (base *CountedOption) GetLongName() string
- func (base *CountedOption) GetMetavar() string
- func (base *CountedOption) GetNargs() Nargs
- func (base *CountedOption) GetRequired() bool
- func (base *CountedOption) GetShortName() string
- func (base *CountedOption) GetUsage() string
- func (countedOption *CountedOption) Set(_ string) error
- func (base *CountedOption) SetChoices(choices ...string)
- func (base *CountedOption) SetConst(value string)
- func (base *CountedOption) SetDefault(value string)
- func (base *CountedOption) SetMetavar(metavar string)
- func (base *CountedOption) SetNargs(nargs Nargs)
- type DefaultProvider
- type FileOption
- func (base *FileOption) GetChoices() []string
- func (base *FileOption) GetConst() string
- func (base *FileOption) GetDefault() *string
- func (base *FileOption) GetLongName() string
- func (base *FileOption) GetMetavar() string
- func (base *FileOption) GetNargs() Nargs
- func (base *FileOption) GetRequired() bool
- func (base *FileOption) GetShortName() string
- func (base *FileOption) GetUsage() string
- func (fileOption *FileOption) Set(in string) error
- func (base *FileOption) SetChoices(choices ...string)
- func (base *FileOption) SetConst(value string)
- func (base *FileOption) SetDefault(value string)
- func (base *FileOption) SetMetavar(metavar string)
- func (base *FileOption) SetNargs(nargs Nargs)
- type IntOption
- func (base *IntOption) GetChoices() []string
- func (base *IntOption) GetConst() string
- func (base *IntOption) GetDefault() *string
- func (base *IntOption) GetLongName() string
- func (base *IntOption) GetMetavar() string
- func (base *IntOption) GetNargs() Nargs
- func (base *IntOption) GetRequired() bool
- func (base *IntOption) GetShortName() string
- func (base *IntOption) GetUsage() string
- func (intOption *IntOption) NormalizeChoice(in string) (string, error)
- func (intOption *IntOption) Set(in string) error
- func (base *IntOption) SetChoices(choices ...string)
- func (base *IntOption) SetConst(value string)
- func (base *IntOption) SetDefault(value string)
- func (base *IntOption) SetMetavar(metavar string)
- func (base *IntOption) SetNargs(nargs Nargs)
- type IntsOption
- func (base *IntsOption) GetChoices() []string
- func (base *IntsOption) GetConst() string
- func (base *IntsOption) GetDefault() *string
- func (base *IntsOption) GetLongName() string
- func (base *IntsOption) GetMetavar() string
- func (base *IntsOption) GetNargs() Nargs
- func (base *IntsOption) GetRequired() bool
- func (base *IntsOption) GetShortName() string
- func (base *IntsOption) GetUsage() string
- func (intsOption *IntsOption) NormalizeChoice(in string) (string, error)
- func (intsOption *IntsOption) Set(in string) error
- func (base *IntsOption) SetChoices(choices ...string)
- func (base *IntsOption) SetConst(value string)
- func (base *IntsOption) SetDefault(value string)
- func (base *IntsOption) SetMetavar(metavar string)
- func (base *IntsOption) SetNargs(nargs Nargs)
- type Nargs
- type Option
- type StringOption
- func (base *StringOption) GetChoices() []string
- func (base *StringOption) GetConst() string
- func (base *StringOption) GetDefault() *string
- func (base *StringOption) GetLongName() string
- func (base *StringOption) GetMetavar() string
- func (base *StringOption) GetNargs() Nargs
- func (base *StringOption) GetRequired() bool
- func (base *StringOption) GetShortName() string
- func (base *StringOption) GetUsage() string
- func (stringOption *StringOption) Set(in string) error
- func (base *StringOption) SetChoices(choices ...string)
- func (base *StringOption) SetConst(value string)
- func (base *StringOption) SetDefault(value string)
- func (base *StringOption) SetMetavar(metavar string)
- func (base *StringOption) SetNargs(nargs Nargs)
- type StringsOption
- func (base *StringsOption) GetChoices() []string
- func (base *StringsOption) GetConst() string
- func (base *StringsOption) GetDefault() *string
- func (base *StringsOption) GetLongName() string
- func (base *StringsOption) GetMetavar() string
- func (base *StringsOption) GetNargs() Nargs
- func (base *StringsOption) GetRequired() bool
- func (base *StringsOption) GetShortName() string
- func (base *StringsOption) GetUsage() string
- func (stringsOption *StringsOption) Set(in string) error
- func (base *StringsOption) SetChoices(choices ...string)
- func (base *StringsOption) SetConst(value string)
- func (base *StringsOption) SetDefault(value string)
- func (base *StringsOption) SetMetavar(metavar string)
- func (base *StringsOption) SetNargs(nargs Nargs)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithChoices ¶
WithChoices restricts an option to the given values and returns it, so that it may be declared inside an option list.
func WithDefault ¶
WithDefault gives an option the value it takes when no argument names it, and returns it.
func WithMetavar ¶
WithMetavar names an option's argument in the help message, and returns it. A positional is named this way: its metavar is what the help calls it, having no option name to go by.
Types ¶
type BoolOption ¶
type BoolOption struct {
Value *bool
// contains filtered or unexported fields
}
BoolOption takes no argument and records that the option was present.
func NewBoolOption ¶
func (*BoolOption) GetChoices ¶
func (base *BoolOption) GetChoices() []string
func (*BoolOption) GetDefault ¶
func (base *BoolOption) GetDefault() *string
func (*BoolOption) GetLongName ¶
func (base *BoolOption) GetLongName() string
func (*BoolOption) GetMetavar ¶
func (base *BoolOption) GetMetavar() string
func (*BoolOption) GetRequired ¶
func (base *BoolOption) GetRequired() bool
func (*BoolOption) GetShortName ¶
func (base *BoolOption) GetShortName() string
GetShortName returns the option's short name, or the empty string when it has none. A zero ShortName must not render as "\x00": that is a name like any other, and every option lacking a short name would collide on it.
func (*BoolOption) Set ¶
func (boolOption *BoolOption) Set(_ string) error
func (*BoolOption) SetChoices ¶
func (base *BoolOption) SetChoices(choices ...string)
func (*BoolOption) SetDefault ¶
func (base *BoolOption) SetDefault(value string)
func (*BoolOption) SetMetavar ¶
func (base *BoolOption) SetMetavar(metavar string)
type ChoiceNormalizer ¶
ChoiceNormalizer is implemented by options whose values have more than one spelling, so that choices may be compared in a single form. An option that does not implement it has its choices compared against the argument as written.
type ChoicesProvider ¶
type ChoicesProvider interface {
GetChoices() []string
}
ChoicesProvider is implemented by options that accept only certain values. Every option built by this package implements it; a hand-written Option may.
type ConstProvider ¶
type ConstProvider interface {
GetConst() string
}
ConstProvider is implemented by NargsOptional options, supplying the value to use when the option is given without an argument.
type CountedOption ¶
type CountedOption struct {
Count *int
// contains filtered or unexported fields
}
CountedOption takes no argument and counts how many times the option was given.
func NewCountedOption ¶
func (*CountedOption) GetChoices ¶
func (base *CountedOption) GetChoices() []string
func (*CountedOption) GetDefault ¶
func (base *CountedOption) GetDefault() *string
func (*CountedOption) GetLongName ¶
func (base *CountedOption) GetLongName() string
func (*CountedOption) GetMetavar ¶
func (base *CountedOption) GetMetavar() string
func (*CountedOption) GetRequired ¶
func (base *CountedOption) GetRequired() bool
func (*CountedOption) GetShortName ¶
func (base *CountedOption) GetShortName() string
GetShortName returns the option's short name, or the empty string when it has none. A zero ShortName must not render as "\x00": that is a name like any other, and every option lacking a short name would collide on it.
func (*CountedOption) Set ¶
func (countedOption *CountedOption) Set(_ string) error
func (*CountedOption) SetChoices ¶
func (base *CountedOption) SetChoices(choices ...string)
func (*CountedOption) SetDefault ¶
func (base *CountedOption) SetDefault(value string)
func (*CountedOption) SetMetavar ¶
func (base *CountedOption) SetMetavar(metavar string)
type DefaultProvider ¶
type DefaultProvider interface {
GetDefault() *string
}
DefaultProvider is implemented by options that are set to a value when no argument names them. The value is nil when no default was declared, which is what distinguishes having no default from defaulting to the empty string.
type FileOption ¶
type FileOption struct {
File *os.File
Flag int
Mode os.FileMode
// contains filtered or unexported fields
}
FileOption opens the path it is given with Flag and Mode, as os.OpenFile does.
func NewFileOption ¶
func NewFileOption(shortName rune, longName string, usage string, required bool, file *os.File) *FileOption
NewFileOption returns a FileOption that opens the path for reading. Use NewFileOptionExtra to choose the flag and mode.
func NewFileOptionExtra ¶
func (*FileOption) GetChoices ¶
func (base *FileOption) GetChoices() []string
func (*FileOption) GetDefault ¶
func (base *FileOption) GetDefault() *string
func (*FileOption) GetLongName ¶
func (base *FileOption) GetLongName() string
func (*FileOption) GetMetavar ¶
func (base *FileOption) GetMetavar() string
func (*FileOption) GetRequired ¶
func (base *FileOption) GetRequired() bool
func (*FileOption) GetShortName ¶
func (base *FileOption) GetShortName() string
GetShortName returns the option's short name, or the empty string when it has none. A zero ShortName must not render as "\x00": that is a name like any other, and every option lacking a short name would collide on it.
func (*FileOption) Set ¶
func (fileOption *FileOption) Set(in string) error
func (*FileOption) SetChoices ¶
func (base *FileOption) SetChoices(choices ...string)
func (*FileOption) SetDefault ¶
func (base *FileOption) SetDefault(value string)
func (*FileOption) SetMetavar ¶
func (base *FileOption) SetMetavar(metavar string)
type IntOption ¶
type IntOption struct {
Value *int
// contains filtered or unexported fields
}
IntOption stores the argument it is given as an int, replacing any previous value.
func NewIntOption ¶
func (*IntOption) GetChoices ¶
func (base *IntOption) GetChoices() []string
func (*IntOption) GetDefault ¶
func (base *IntOption) GetDefault() *string
func (*IntOption) GetLongName ¶
func (base *IntOption) GetLongName() string
func (*IntOption) GetMetavar ¶
func (base *IntOption) GetMetavar() string
func (*IntOption) GetRequired ¶
func (base *IntOption) GetRequired() bool
func (*IntOption) GetShortName ¶
func (base *IntOption) GetShortName() string
GetShortName returns the option's short name, or the empty string when it has none. A zero ShortName must not render as "\x00": that is a name like any other, and every option lacking a short name would collide on it.
func (*IntOption) NormalizeChoice ¶
NormalizeChoice renders an int the one way, so that a choice of "7" also admits "007" and "+7".
func (*IntOption) SetChoices ¶
func (base *IntOption) SetChoices(choices ...string)
func (*IntOption) SetDefault ¶
func (base *IntOption) SetDefault(value string)
func (*IntOption) SetMetavar ¶
func (base *IntOption) SetMetavar(metavar string)
type IntsOption ¶
type IntsOption struct {
Value *[]int
// contains filtered or unexported fields
}
IntsOption appends each argument it is given to a slice of ints.
func NewIntsOption ¶
func (*IntsOption) GetChoices ¶
func (base *IntsOption) GetChoices() []string
func (*IntsOption) GetDefault ¶
func (base *IntsOption) GetDefault() *string
func (*IntsOption) GetLongName ¶
func (base *IntsOption) GetLongName() string
func (*IntsOption) GetMetavar ¶
func (base *IntsOption) GetMetavar() string
func (*IntsOption) GetRequired ¶
func (base *IntsOption) GetRequired() bool
func (*IntsOption) GetShortName ¶
func (base *IntsOption) GetShortName() string
GetShortName returns the option's short name, or the empty string when it has none. A zero ShortName must not render as "\x00": that is a name like any other, and every option lacking a short name would collide on it.
func (*IntsOption) NormalizeChoice ¶
func (intsOption *IntsOption) NormalizeChoice(in string) (string, error)
NormalizeChoice renders an int the one way, so that a choice of "7" also admits "007" and "+7".
func (*IntsOption) Set ¶
func (intsOption *IntsOption) Set(in string) error
func (*IntsOption) SetChoices ¶
func (base *IntsOption) SetChoices(choices ...string)
func (*IntsOption) SetDefault ¶
func (base *IntsOption) SetDefault(value string)
func (*IntsOption) SetMetavar ¶
func (base *IntsOption) SetMetavar(metavar string)
type Nargs ¶
type Nargs string
Nargs describes how many arguments an option consumes.
const ( // NargsOne marks an option that consumes exactly one argument. It is the zero value, so an // option that does not say otherwise takes one argument. NargsOne Nargs = "" // NargsNone marks an option that takes no argument, such as a flag or a counter. NargsNone Nargs = "0" // NargsOptional marks an option whose argument may be omitted. Given without one, it is set to // its constant instead. NargsOptional Nargs = "?" // NargsAtLeastOne marks an option that may be given repeatedly, accumulating its arguments, and // must be given at least once. NargsAtLeastOne Nargs = "+" // NargsAny is NargsAtLeastOne without the obligation: it accumulates, and may be left out. NargsAny Nargs = "*" )
func (Nargs) IsVariadic ¶
IsVariadic reports whether an arity accumulates its arguments rather than taking a fixed number.
type Option ¶
type Option interface {
Set(string) error
GetShortName() string
GetLongName() string
GetUsage() string
GetRequired() bool
GetNargs() Nargs
GetMetavar() string
}
Option is a single command-line option, addressable by a short name, a long name, or both.
type StringOption ¶
type StringOption struct {
Value *string
// contains filtered or unexported fields
}
StringOption stores the argument it is given, replacing any previous value.
func NewStringOption ¶
func (*StringOption) GetChoices ¶
func (base *StringOption) GetChoices() []string
func (*StringOption) GetDefault ¶
func (base *StringOption) GetDefault() *string
func (*StringOption) GetLongName ¶
func (base *StringOption) GetLongName() string
func (*StringOption) GetMetavar ¶
func (base *StringOption) GetMetavar() string
func (*StringOption) GetRequired ¶
func (base *StringOption) GetRequired() bool
func (*StringOption) GetShortName ¶
func (base *StringOption) GetShortName() string
GetShortName returns the option's short name, or the empty string when it has none. A zero ShortName must not render as "\x00": that is a name like any other, and every option lacking a short name would collide on it.
func (*StringOption) Set ¶
func (stringOption *StringOption) Set(in string) error
func (*StringOption) SetChoices ¶
func (base *StringOption) SetChoices(choices ...string)
func (*StringOption) SetDefault ¶
func (base *StringOption) SetDefault(value string)
func (*StringOption) SetMetavar ¶
func (base *StringOption) SetMetavar(metavar string)
type StringsOption ¶
type StringsOption struct {
Value *[]string
// contains filtered or unexported fields
}
StringsOption appends each argument it is given to a slice of strings.
func NewStringsOption ¶
func (*StringsOption) GetChoices ¶
func (base *StringsOption) GetChoices() []string
func (*StringsOption) GetDefault ¶
func (base *StringsOption) GetDefault() *string
func (*StringsOption) GetLongName ¶
func (base *StringsOption) GetLongName() string
func (*StringsOption) GetMetavar ¶
func (base *StringsOption) GetMetavar() string
func (*StringsOption) GetRequired ¶
func (base *StringsOption) GetRequired() bool
func (*StringsOption) GetShortName ¶
func (base *StringsOption) GetShortName() string
GetShortName returns the option's short name, or the empty string when it has none. A zero ShortName must not render as "\x00": that is a name like any other, and every option lacking a short name would collide on it.
func (*StringsOption) Set ¶
func (stringsOption *StringsOption) Set(in string) error
func (*StringsOption) SetChoices ¶
func (base *StringsOption) SetChoices(choices ...string)
func (*StringsOption) SetDefault ¶
func (base *StringsOption) SetDefault(value string)
func (*StringsOption) SetMetavar ¶
func (base *StringsOption) SetMetavar(metavar string)