Documentation
¶
Index ¶
- Variables
- func DefaultUsage(flagSet *flag.FlagSet)
- func GetIgnoredArgs() []string
- func Parse() error
- func PrintDefaults()
- func PrintFlagSetDefaults(flagSet *flag.FlagSet)
- func SetAllowParsingMultipleAliases(allow bool)
- func SetIgnoreUnknown(ignore bool)
- func StripUnknownFlags(flagSet *flag.FlagSet, args []string) (res, stripped []string)
- func StructVar(p any, ignoredFields ...any) error
- func StructVarWithPrefix(p any, flagsPrefix string, ignoredFields ...any) error
- type FlagSet
- func (fls *FlagSet) GetIgnoredArgs() []string
- func (fls *FlagSet) Parse(arguments []string) error
- func (fls *FlagSet) PrintDefaults()
- func (fls *FlagSet) SetAllowParsingMultipleAliases(allow bool)
- func (fls *FlagSet) SetIgnoreUnknown(ignore bool)
- func (fls *FlagSet) StructVar(p any, ignoredFields ...any) error
- func (fls *FlagSet) StructVarWithPrefix(p any, flagsPrefix string, ignoredFields ...any) error
Constants ¶
This section is empty.
Variables ¶
var CommandLine = Wrap(flag.CommandLine)
CommandLine is a default FlagSet that is used by the package functions. It's a wrapper around flag.CommandLine to follow the same pattern as in the stdlib.
var Usage = func() { printUsageTitle(CommandLine.FlagSet, os.Args[0]) PrintDefaults() }
Functions ¶
func DefaultUsage ¶
DefaultUsage prints the default FlagSet usage to flagSet.Output grouping alternative flag names
func GetIgnoredArgs ¶ added in v1.0.1
func GetIgnoredArgs() []string
GetIgnoredArgs returns a slice of arguments that were ignored during the last call to Parse() because of SetIgnoreUnknown(true), nil otherwise
func PrintDefaults ¶
func PrintDefaults()
PrintDefaults prints the default FlagSet usage to stdout grouping alternative flag names
func PrintFlagSetDefaults ¶
PrintFlagSetDefaults prints flag names and usage grouping alternative flag names
func SetAllowParsingMultipleAliases ¶
func SetAllowParsingMultipleAliases(allow bool)
SetAllowParsingMultipleAliases sets the behavior of Parse() when multiple tag names assigned to same field are passed. If `true`, it will be ignored and only the last value will be used. If `false`, Parse() will return an error. Default value is `false`.
func SetIgnoreUnknown ¶ added in v1.0.0
func SetIgnoreUnknown(ignore bool)
SetIgnoreUnknown sets the behavior of Parse() when unknown flags are passed. If `true`, they will be ignored. If `false`, Parse() will return an error. Default value is `false`.
func StripUnknownFlags ¶ added in v1.0.0
func StructVar ¶
StructVar registers the given struct with the default FlagSet `ignoredFields` is a slice of pointers to fields that should be ignored and not registered as flags See FlagSet.StructVar
func StructVarWithPrefix ¶
StructVarWithPrefix registers the given struct with the default FlagSet using the given prefix for flag names. `ignoredFields` is a slice of pointers to fields that should be ignored and not registered as flags See FlagSet.StructVarWithPrefix
Types ¶
type FlagSet ¶
FlagSet is a wrapper around *flag.FlagSet that allows to register structs parsing their fields as flags.
func NewFlagSet ¶
func NewFlagSet(name string, errorHandling flag.ErrorHandling) *FlagSet
NewFlagSet creates a new FlagSet wrapping new flag.FlagSet with the given name and error handling policy and assigns its Usage to the own implementation that groups alternative flag names
func Wrap ¶
Wrap creates a new FlagSet wrapping the given `stdFlagSet` and does not set stdFlagSet.Usage
func (*FlagSet) GetIgnoredArgs ¶ added in v1.0.1
GetIgnoredArgs returns a slice of arguments that were ignored during the last call to Parse() because of SetIgnoreUnknown(true), nil otherwise
func (*FlagSet) Parse ¶
Parse parses the command-line flags calling Parse on the wrapped FlagSet and then sets values of the registered structs fields for flags that were actually parsed.
func (*FlagSet) PrintDefaults ¶
func (fls *FlagSet) PrintDefaults()
PrintDefaults prints the default FlagSet usage to wrapped FlagSet.Output grouping alternative flag names
func (*FlagSet) SetAllowParsingMultipleAliases ¶
SetAllowParsingMultipleAliases sets the behavior of Parse() when multiple tag names assigned to same field are passed. If `true`, it will be ignored and only the last value will be used. If `false`, Parse() will return an error. Default value is `false`.
func (*FlagSet) SetIgnoreUnknown ¶ added in v1.0.0
SetIgnoreUnknown sets the behavior of Parse() when unknown flags are passed. If `true`, they will be ignored. If `false`, Parse() will return an error. Default value is `false`.
func (*FlagSet) StructVar ¶
StructVar registers the fields of the given struct as a flags `ignoredFields` is a slice of pointers to fields that should be ignored and not registered as flags
func (*FlagSet) StructVarWithPrefix ¶
StructVarWithPrefix registers the fields of the given struct as a flags with names prefixed with `flagsPrefix` `ignoredFields` is a slice of pointers to fields that should be ignored and not registered as flags