Documentation
¶
Overview ¶
Package flagx implements extensions to the standard flag package in the form of types that implement flag.Value
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolFunc ¶ added in v0.22.2
BoolFunc defines a flag with the specified name and usage string. Each time the flag is set with a truthy value, fn is called. If fn returns a non-nil error, it will be treated as a flag value parsing error.
func Missing ¶
Missing returns a slice of required flags missing from an error returned by MustHave.
func MustHave ¶
MustHave is a convenience function that checks that the named flags were set on fl. Missing flags are treated with the policy of fl.ErrorHandling(): ExitOnError, ContinueOnError, or PanicOnError. Returned errors can be unpacked by Missing.
If nil, fl defaults to flag.CommandLine.
Example (MissingFlag) ¶
Output: missing required flag: b Usage of ExampleMustHave: -a string this value must be set -b string this value must be set -c string this value is optional Missing: [b]
func MustHaveArgs ¶
MustHaveArgs is a convenience function that checks that fl.NArg() is within the bounds min and max (inclusive). Use max -1 to indicate no maximum value. MustHaveArgs uses the policy of fl.ErrorHandling(): ExitOnError, ContinueOnError, or PanicOnError.
If nil, fl defaults to flag.CommandLine.
Example (WrongNumber) ¶
Output: must have between 0 and 1 args; got 2 Usage: ExampleMustHaveArgs [optional arg]
Types ¶
This section is empty.