Documentation
¶
Index ¶
- Variables
- func DefaultUsage(flagSet *flag.FlagSet)
- 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) []string
- func StructVar(p any) error
- func StructVarWithPrefix(p any, flagsPrefix string) error
- type FlagSet
- 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) error
- func (fls *FlagSet) StructVarWithPrefix(p any, flagsPrefix string) 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 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 See FlagSet.StructVar
func StructVarWithPrefix ¶
StructVarWithPrefix registers the given struct with the default FlagSet using the given prefix for flag names. 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) 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`.