Documentation
¶
Overview ¶
Package flagpole - Go package for reading CLI flags into a struct
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckRequiredFlags ¶
type CheckRequiredFlags bool
CheckRequiredFlags is a type that can be passed as an option to NewParser or Parser.Parse and instructs the parser whether to check that required flags were specified (the default is true)
type DefaultedOptionals ¶
type DefaultedOptionals bool
DefaultedOptionals is a type that can be passed as an option to NewParser or Parser.Parse and instructs the parser to fill optional flags with their default value (if present) when the flag was not specified (default is false)
type DuplicateFlag ¶
type DuplicateFlag int
DuplicateFlag is a type that can be passed as an option to NewParser or Parser.Parse and instructs the parser how to deal with duplicate fields (the default is DuplicateFlagOverwrite)
const ( DuplicateFlagOverwrite DuplicateFlag = iota DuplicateFlagIgnore DuplicateFlagError )
type Flag ¶
type Flag struct {
Name string // name as it appears on command line
Usage string // help message
HasDefault bool // whether the flag has a default value (DefValue)
DefValue string // default value (as text); for usage message
IsBool bool // denotes if the flag is a bool
Required bool // denotes the flag is required
Aliases []string // denotes alias names for the flag
Example string // example; for usage message
}
Flag represents a flag extracted from a struct
type IgnoreUnknownFlags ¶
type IgnoreUnknownFlags bool
IgnoreUnknownFlags is a type that can be passed as an option to NewParser or Parser.Parse and determines whether the parser should ignore unknown flags (default is false)
type ParseErrorHandler ¶
type ParseErrorHandler interface {
// HandleError is called with errors during parsing
//
// - name is the flag name
// - flag is the flag information (if known)
// - err is the error encountered
//
// return true if parsing is to continue, otherwise parsing halts with the error
HandleError(name string, flag *Flag, err error) (cont bool)
}
ParseErrorHandler is an interface that can be passed as an option to NewParser or Parser.Parse and is called with all errors during parsing - and allows continuation after error
type Parser ¶
type Parser[T any] interface { // Parse parses the supplied arguments as flags and returns the crated struct for those flags // // any options supplied override the options for the parser Parse(arguments []string, options ...any) (T, error) // Flags returns the flags found in the struct Flags() []Flag // Usage prints the usage information about flags to the supplied out (e.g. os.Stdout, os.Stderr) Usage(out io.Writer, err error, commandPrefixes ...string) }
Parser is the flags parser - use NewParser / MustNewParser to create a new one
func MustNewParser ¶
MustNewParser is the same as NewParser, except it panics on error
type StopOnFlag ¶
type StopOnFlag string
StopOnFlag is a type that can be passed as an option to NewParser or Parser.Parse and instructs the parser to stop on seeing the specified flag
Multiple of these can be passed as options - they become additive
type StopOnHelp ¶
type StopOnHelp bool
StopOnHelp is a type that can be passed as an option to NewParser or Parser.Parse and instructs the parser to stop on encountering flag "-help" / "-h"