Documentation ¶
Index ¶
- Variables
- func CombineFlags(f0, f1 *flag.Flag) *flag.Flag
- func CombineSets(fs0, fs1 *flag.FlagSet) *flag.FlagSet
- func Copy(dst, src *flag.FlagSet)
- func LinkFlag(fs *flag.FlagSet, src, dst string)
- func MergeInto(super *flag.FlagSet, setup func(*flag.FlagSet))
- func OverrideSet(v flag.Value, f func(string) error) flag.Value
- func Parse(ctx context.Context, flags *flag.FlagSet, opts ...ParseOption) (err error)
- func PrintDefaults(ctx context.Context, flags *flag.FlagSet, opts ...ParseOption) error
- func SetActual(fs *flag.FlagSet, name string)
- func Subset(super *flag.FlagSet, prefix string, setup func(sub *flag.FlagSet)) (err error)
- type ParseOption
- type ParseOptionFunc
- type ParseOrParserOptionFunc
- type Parser
- type ParserFunc
- type ParserOption
- type ParserOptionFunc
- type Printer
- type PrinterFunc
- type UnquoteUsageMode
Constants ¶
This section is empty.
Variables ¶
var MergeUsage = func(name string, usage0, usage1 string) string {
return usage0 + " / " + usage1
}
MergeUsage specifies way of joining two different flag usage strings.
var SetSeparator = "."
Functions ¶
func CombineFlags ¶ added in v0.8.0
CombineFlags combines given flags into a third one. Setting value of returned flag will cause both given flags change their values as well. However, flag sets of both flags will not be aware that the flags were set.
Description of each flag (if differ) is joined by MergeUsage().
func CombineSets ¶ added in v0.8.0
CombineSets combines given sets into a third one. Every collided flags are combined into third one in a way that setting value to it sets value of both original flags.
func Copy ¶ added in v0.9.0
Copy defines all flags from src with dst. It panics on any flag name collision.
func LinkFlag ¶ added in v0.11.0
LinkFlag links dst to be updated when src value is set. It panics if any of the given names doesn't exist in fs.
Note that it caches the both src and dst flag.Value pointers internally, so it is possible to link src to dst and dst to src without infinite recursion. However, if any of the src or dst flag value get overwritten after LinkFlag() call, created link will not work properly anymore.
func MergeInto ¶ added in v0.8.0
MergeInto merges new flagset into superset and resolves any name collisions. It calls setup function to let caller register needed flags within subset before they are merged into the superset.
If name of the flag defined in the subset already present in a superset, then subset flag is merged into superset's one. That is, flag will remain in the superset, but setting its value will make both parameters filled with received value.
Description of each flag (if differ) is joined by MergeUsage().
Note that default values (and initial values of where flag.Value points to) are kept untouched and may differ if no value is set during parsing phase.
func OverrideSet ¶ added in v0.8.0
OverrideSet returns a wrapper around v which Set() method is replaced by f.
func PrintDefaults ¶ added in v0.3.0
PrintDefaults prints parsers aware usage message to flags.Output().
Types ¶
type ParseOption ¶
type ParseOption interface {
// contains filtered or unexported methods
}
type ParseOptionFunc ¶ added in v0.4.0
type ParseOptionFunc func(*config)
func WithCustomUsage ¶ added in v0.4.0
func WithCustomUsage() ParseOptionFunc
WithCustomUsage makes Parse() to ignore flag.FlagSet.Usage field when receiving flag.ErrHelp error from some parser and print results of flagutil.PrintDefaults() instead.
func WithParseOptions ¶ added in v0.5.0
func WithParseOptions(opts ...ParseOption) ParseOptionFunc
func WithParser ¶
func WithParser(p Parser, opts ...ParserOption) ParseOptionFunc
WithParser returns a parse option and makes p to be used during Parse().
func WithUnquoteUsageMode ¶ added in v0.3.0
func WithUnquoteUsageMode(m UnquoteUsageMode) ParseOptionFunc
type ParseOrParserOptionFunc ¶ added in v0.9.0
type ParseOrParserOptionFunc func(*config, *parser)
func WithAllowResetSpecified ¶ added in v0.9.0
func WithAllowResetSpecified() (opt ParseOrParserOptionFunc)
func WithIgnoreUndefined ¶
func WithIgnoreUndefined() (opt ParseOrParserOptionFunc)
WithIgnoreUndefined makes Parse() to not fail on setting undefined flag.
func WithStashName ¶ added in v0.4.0
func WithStashName(name string) ParseOrParserOptionFunc
func WithStashPrefix ¶ added in v0.4.0
func WithStashPrefix(prefix string) ParseOrParserOptionFunc
func WithStashRegexp ¶ added in v0.4.0
func WithStashRegexp(re *regexp.Regexp) ParseOrParserOptionFunc
type ParserFunc ¶ added in v0.3.0
type ParserOption ¶ added in v0.3.0
type ParserOption interface {
// contains filtered or unexported methods
}
type ParserOptionFunc ¶ added in v0.4.0
type ParserOptionFunc func(*parser)
func WithResetSpecified ¶ added in v0.9.0
func WithResetSpecified() ParserOptionFunc
type PrinterFunc ¶ added in v0.3.0
type UnquoteUsageMode ¶ added in v0.3.0
type UnquoteUsageMode uint8
const ( UnquoteNothing UnquoteUsageMode = 1 << iota >> 1 UnquoteQuoted UnquoteInferType UnquoteClean UnquoteDefault UnquoteUsageMode = UnquoteQuoted | UnquoteInferType )
func (UnquoteUsageMode) String ¶ added in v0.3.0
func (m UnquoteUsageMode) String() string