Documentation
¶
Index ¶
- Variables
- func Arg(i int) string
- func Args() []string
- func Bool(flag string, value bool, description string) *bool
- func BoolP(short rune, long string, value bool, description string) *bool
- func BoolVar(pv *bool, flag string, value bool, description string)
- func BoolVarP(pv *bool, short rune, long string, value bool, description string)
- func Duration(flag string, value time.Duration, description string) *time.Duration
- func DurationP(short rune, long string, value time.Duration, description string) *time.Duration
- func DurationVar(pv *time.Duration, flag string, value time.Duration, description string)
- func DurationVarP(pv *time.Duration, short rune, long string, value time.Duration, ...)
- func Float(flag string, value float64, description string) *float64
- func FloatP(short rune, long string, value float64, description string) *float64
- func FloatVar(pv *float64, flag string, value float64, description string)
- func FloatVarP(pv *float64, short rune, long string, value float64, description string)
- func Int(flag string, value int, description string) *int
- func Int64(flag string, value int64, description string) *int64
- func Int64P(short rune, long string, value int64, description string) *int64
- func Int64Var(pv *int64, flag string, value int64, description string)
- func Int64VarP(pv *int64, short rune, long string, value int64, description string)
- func IntP(short rune, long string, value int, description string) *int
- func IntVar(pv *int, flag string, value int, description string)
- func IntVarP(pv *int, short rune, long string, value int, description string)
- func NArg() int
- func NFlag() int
- func Parse()
- func Parsed() bool
- func PrintDefaults()
- func PrintDefaultsTo(w io.Writer)
- func String(flag string, value string, description string) *string
- func StringP(short rune, long string, value string, description string) *string
- func StringVar(pv *string, flag string, value string, description string)
- func StringVarP(pv *string, short rune, long string, value string, description string)
- func Uint(flag string, value uint, description string) *uint
- func Uint64(flag string, value uint64, description string) *uint64
- func Uint64P(short rune, long string, value uint64, description string) *uint64
- func Uint64Var(pv *uint64, flag string, value uint64, description string)
- func Uint64VarP(pv *uint64, short rune, long string, value uint64, description string)
- func UintP(short rune, long string, value uint, description string) *uint
- func UintVar(pv *uint, flag string, value uint, description string)
- func UintVarP(pv *uint, short rune, long string, value uint, description string)
- func Wrap(input string) string
- type LineWrapper
- type Parser
- func (p *Parser) Arg(i int) string
- func (p *Parser) Args() []string
- func (p *Parser) Err() error
- func (p *Parser) NArg() int
- func (p *Parser) NFlag() int
- func (p *Parser) Parse(args []string) error
- func (p Parser) Parsed() bool
- func (p *Parser) PrintDefaults()
- func (p *Parser) PrintDefaultsTo(w io.Writer)
- func (p *Parser) WithBool(flag string, value bool, description string) *bool
- func (p *Parser) WithBoolP(short rune, long string, value bool, description string) *bool
- func (p *Parser) WithBoolVar(pv *bool, flag string, description string) *Parser
- func (p *Parser) WithBoolVarP(pv *bool, short rune, long string, description string) *Parser
- func (p *Parser) WithDuration(flag string, value time.Duration, description string) *time.Duration
- func (p *Parser) WithDurationP(short rune, long string, value time.Duration, description string) *time.Duration
- func (p *Parser) WithDurationVar(pv *time.Duration, flag string, description string) *Parser
- func (p *Parser) WithDurationVarP(pv *time.Duration, short rune, long string, description string) *Parser
- func (p *Parser) WithFloat(flag string, value float64, description string) *float64
- func (p *Parser) WithFloatP(short rune, long string, value float64, description string) *float64
- func (p *Parser) WithFloatVar(pv *float64, flag string, description string) *Parser
- func (p *Parser) WithFloatVarP(pv *float64, short rune, long string, description string) *Parser
- func (p *Parser) WithInt(flag string, value int, description string) *int
- func (p *Parser) WithInt64(flag string, value int64, description string) *int64
- func (p *Parser) WithInt64P(short rune, long string, value int64, description string) *int64
- func (p *Parser) WithInt64Var(pv *int64, flag string, description string) *Parser
- func (p *Parser) WithInt64VarP(pv *int64, short rune, long string, description string) *Parser
- func (p *Parser) WithIntP(short rune, long string, value int, description string) *int
- func (p *Parser) WithIntVar(pv *int, flag string, description string) *Parser
- func (p *Parser) WithIntVarP(pv *int, short rune, long string, description string) *Parser
- func (p *Parser) WithString(flag string, value string, description string) *string
- func (p *Parser) WithStringP(short rune, long string, value string, description string) *string
- func (p *Parser) WithStringVar(pv *string, flag string, description string) *Parser
- func (p *Parser) WithStringVarP(pv *string, short rune, long string, description string) *Parser
- func (p *Parser) WithUint(flag string, value uint, description string) *uint
- func (p *Parser) WithUint64(flag string, value uint64, description string) *uint64
- func (p *Parser) WithUint64P(short rune, long string, value uint64, description string) *uint64
- func (p *Parser) WithUint64Var(pv *uint64, flag string, description string) *Parser
- func (p *Parser) WithUint64VarP(pv *uint64, short rune, long string, description string) *Parser
- func (p *Parser) WithUintP(short rune, long string, value uint, description string) *uint
- func (p *Parser) WithUintVar(pv *uint, flag string, description string) *Parser
- func (p *Parser) WithUintVarP(pv *uint, short rune, long string, description string) *Parser
Constants ¶
This section is empty.
Variables ¶
var Usage = func() { fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) defaultParser.PrintDefaults() }
Usage prints command line usage to stderr, but may be overridden by programs that need to customize the usage information.
Functions ¶
func Arg ¶
Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed. Arg returns an empty string if the requested element does not exist.
func Bool ¶
Bool returns a pointer to a bool command line option, allowing for either a short or a long flag. If both are desired, use the BoolP function.
func BoolP ¶ added in v0.1.0
BoolP returns a pointer to a bool command line option, allowing for both a short and a long flag.
func BoolVar ¶ added in v0.0.4
BoolVar binds an existing boolean variable to a flag, allowing for either a short or a long flag. If both are desired, use the BoolVarP function.
func BoolVarP ¶ added in v0.1.0
BoolVarP binds an existing boolean variable to a flag, allowing for both a short and a long flag.
func Duration ¶
Duration returns a pointer to a time.Duration command line option, allowing for either a short or a long flag. If both are desired, use the DurationP function.
func DurationP ¶ added in v0.1.0
DurationP returns a pointer to a time.Duration command line option, allowing for both a short and a long flag.
func DurationVar ¶ added in v0.0.4
DurationVar binds an existing time.Duration variable to a flag, allowing for either a short or a long flag. If both are desired, use the DurationVarP function.
func DurationVarP ¶ added in v0.1.0
func DurationVarP(pv *time.Duration, short rune, long string, value time.Duration, description string)
DurationVarP binds an existing time.Duration variable to a flag, allowing for both a short and a long flag.
func Float ¶
Float returns a pointer to a float64 command line option, allowing for either a short or a long flag. If both are desired, use the FloatP function.
func FloatP ¶ added in v0.1.0
FloatP returns a pointer to a float64 command line option, allowing for both a short and a long flag.
func FloatVar ¶ added in v0.0.4
FloatVar binds an existing float64 variable to a flag, allowing for either a short or a long flag. If both are desired, use the FloatVarP function.
func FloatVarP ¶ added in v0.1.0
FloatVarP binds an existing float64 variable to a flag, allowing for both a short and a long flag.
func Int ¶
Int returns a pointer to a int command line option, allowing for either a short or a long flag. If both are desired, use the IntP function.
func Int64 ¶
Int64 returns a pointer to a int64 command line option, allowing for either a short or a long flag. If both are desired, use the Int64P function.
func Int64P ¶ added in v0.1.0
Int64P returns a pointer to a int64 command line option, allowing for both a short and a long flag.
func Int64Var ¶ added in v0.0.4
Int64Var binds an existing int64 variable to a flag, allowing for either a short or a long flag. If both are desired, use the Int64VarP function.
func Int64VarP ¶ added in v0.1.0
Int64VarP binds an existing int64 variable to a flag, allowing for both a short and a long flag.
func IntP ¶ added in v0.1.0
IntP returns a pointer to a int command line option, allowing for both a short and a long flag.
func IntVar ¶ added in v0.0.4
IntVar binds an existing int variable to a flag, allowing for either a short or a long flag. If both are desired, use the IntVarP function.
func IntVarP ¶ added in v0.1.0
IntVarP binds an existing int variable to a flag, allowing for both a short and a long flag.
func NArg ¶
func NArg() int
NArg returns the number of arguments remaining after flags have been processed.
func NFlag ¶
func NFlag() int
NFlag returns the number of command-line flags that have been processed.
func Parse ¶
func Parse()
Parse parses the command line. On error, displays the usage of the command line and exits the program with status code 2.
func Parsed ¶
func Parsed() bool
Parsed reports whether the command-line flags have been parsed.
Deprecated
func PrintDefaults ¶
func PrintDefaults()
PrintDefaults prints to standard error, a usage message showing the default settings of all defined command-line flags.
func PrintDefaultsTo ¶ added in v1.4.0
PrintDefaultsTo prints to w, a usage message showing the default settings of all defined command-line flags.
func String ¶
String returns a postringer to a string command line option, allowing for either a short or a long flag. If both are desired, use the StringP function.
func StringP ¶ added in v0.1.0
StringP returns a postringer to a string command line option, allowing for both a short and a long flag.
func StringVar ¶ added in v0.0.4
StringVar binds an existing string variable to a flag, allowing for either a short or a long flag. If both are desired, use the StringVarP function.
func StringVarP ¶ added in v0.1.0
StringVarP binds an existing string variable to a flag, allowing for both a short and a long flag.
func Uint ¶
Uint returns a pouinter to a uint command line option, allowing for either a short or a long flag. If both are desired, use the UintP function.
func Uint64 ¶
Uint64 returns a pointer to a uint64 command line option, allowing for either a short or a long flag. If both are desired, use the Uint64P function.
func Uint64P ¶ added in v0.1.0
Uint64P returns a pointer to a uint64 command line option, allowing for both a short and a long flag.
func Uint64Var ¶ added in v0.0.4
Uint64Var binds an existing uint64 variable to a flag, allowing for either a short or a long flag. If both are desired, use the Uint64VarP function.
func Uint64VarP ¶ added in v0.1.0
Uint64VarP binds an existing uint64 variable to a flag, allowing for both a short and a long flag.
func UintP ¶ added in v0.1.0
UintP returns a pouinter to a uint command line option, allowing for both a short and a long flag.
func UintVar ¶ added in v0.0.4
UintVar binds an existing uint variable to a flag, allowing for either a short or a long flag. If both are desired, use the UintVarP function.
func UintVarP ¶ added in v0.1.0
UintVarP binds an existing uint variable to a flag, allowing for both a short and a long flag.
func Wrap ¶ added in v1.3.0
Wrap returns input string with leading and trailing whitespace removed, with the exception of exactly one trailing newline character, and intraline whitespace normalized to single spaces, except in cases where a word would exceed a line length of 80 columns, in which case a newline will be used rather than a space.
Types ¶
type LineWrapper ¶ added in v1.3.0
type LineWrapper struct { // Prefix is the optional string to be places at the start of every output // line. Prefix string // Max is the optional maximum number of columns to wrap the text to. When // 0, the LineWrapper will wrap lines fit on in 80 columns. Max int }
LineWrapper wraps input strings to specified maximum number of columns, or when zero, 80 columns. When Prefix is not empty string, it prefixes each line with the prefix string.
func (LineWrapper) Wrap ¶ added in v1.3.0
func (w LineWrapper) Wrap(input string) string
type Parser ¶ added in v1.5.0
type Parser struct {
// contains filtered or unexported fields
}
Parser can parse a series of command line arguments.
func (*Parser) Arg ¶ added in v1.5.0
Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed. Arg returns an empty string if the requested element does not exist.
func (*Parser) NArg ¶ added in v1.5.0
NArg returns the number of arguments remaining after flags have been processed.
func (*Parser) NFlag ¶ added in v1.5.0
NFlag returns the number of command-line flags that have been processed.
func (Parser) Parsed ¶ added in v1.5.0
Parsed reports whether the command-line flags have been parsed.
func (*Parser) PrintDefaults ¶ added in v1.5.0
func (p *Parser) PrintDefaults()
PrintDefaults prints to standard error, a usage message showing the default settings of all defined command-line flags.
func (*Parser) PrintDefaultsTo ¶ added in v1.5.0
PrintDefaultsTo prints to w, a usage message showing the default settings of all defined command-line flags.
func (*Parser) WithBool ¶ added in v1.6.0
WithBool returns a pointer to a bool command line option, allowing for either a short or a long flag. If both are desired, use the BoolP function.
func (*Parser) WithBoolP ¶ added in v1.6.0
WithBoolP returns a pointer to a bool command line option, allowing for both a short and a long flag.
func (*Parser) WithBoolVar ¶ added in v1.5.0
WithBoolVar updates the Parser to recognize flag as a bool with the default value and description.
func (*Parser) WithBoolVarP ¶ added in v1.5.0
WithBoolVar updates the Parser to recognize short and long flag as a bool with the default value and description.
func (*Parser) WithDuration ¶ added in v1.6.0
WithDuration returns a pointer to a time.Duration command line option, allowing for either a short or a long flag. If both are desired, use the DurationP function.
func (*Parser) WithDurationP ¶ added in v1.6.0
func (p *Parser) WithDurationP(short rune, long string, value time.Duration, description string) *time.Duration
WithDurationP returns a pointer to a time.Duration command line option, allowing for both a short and a long flag.
func (*Parser) WithDurationVar ¶ added in v1.5.0
WithDurationVar updates the Parser to recognize flag as a duration with the default value and description.
func (*Parser) WithDurationVarP ¶ added in v1.5.0
func (p *Parser) WithDurationVarP(pv *time.Duration, short rune, long string, description string) *Parser
WithDurationVar updates the Parser to recognize short and long flag as a duration with the default value and description.
func (*Parser) WithFloat ¶ added in v1.6.0
WithFloat returns a pointer to a float64 command line option, allowing for either a short or a long flag. If both are desired, use the FloatP function.
func (*Parser) WithFloatP ¶ added in v1.6.0
WithFloatP returns a pointer to a float64 command line option, allowing for both a short and a long flag.
func (*Parser) WithFloatVar ¶ added in v1.5.0
WithFloatVar updates the Parser to recognize flag as a float with the default value and description.
func (*Parser) WithFloatVarP ¶ added in v1.5.0
WithFloatVar updates the Parser to recognize short and long flag as a float with the default value and description.
func (*Parser) WithInt ¶ added in v1.6.0
WithInt returns a pointer to a int command line option, allowing for either a short or a long flag. If both are desired, use the IntP function.
func (*Parser) WithInt64 ¶ added in v1.6.0
WithInt64 returns a pointer to a int64 command line option, allowing for either a short or a long flag. If both are desired, use the Int64P function.
func (*Parser) WithInt64P ¶ added in v1.6.0
WithInt64P returns a pointer to a int64 command line option, allowing for both a short and a long flag.
func (*Parser) WithInt64Var ¶ added in v1.5.0
WithInt64Var updates the Parser to recognize flag as a int64 with the default value and description.
func (*Parser) WithInt64VarP ¶ added in v1.5.0
WithInt64Var updates the Parser to recognize short and long flag as a int64 with the default value and description.
func (*Parser) WithIntP ¶ added in v1.6.0
WithIntP returns a pointer to a int command line option, allowing for both a short and a long flag.
func (*Parser) WithIntVar ¶ added in v1.5.0
WithIntVar updates the Parser to recognize flag as a int with the default value and description.
func (*Parser) WithIntVarP ¶ added in v1.5.0
WithIntVar updates the Parser to recognize short and long flag as a int with the default value and description.
func (*Parser) WithString ¶ added in v1.6.0
WithString returns a postringer to a string command line option, allowing for either a short or a long flag. If both are desired, use the StringP function.
func (*Parser) WithStringP ¶ added in v1.6.0
WithStringP returns a postringer to a string command line option, allowing for both a short and a long flag.
func (*Parser) WithStringVar ¶ added in v1.5.0
WithStringVar updates the Parser to recognize flag as a string with the default value and description.
func (*Parser) WithStringVarP ¶ added in v1.5.0
WithStringVar updates the Parser to recognize short and long flag as a string with the default value and description.
func (*Parser) WithUint ¶ added in v1.6.0
WithUint returns a pouinter to a uint command line option, allowing for either a short or a long flag. If both are desired, use the UintP function.
func (*Parser) WithUint64 ¶ added in v1.6.0
WithUint64 returns a pouinter to a uint64 command line option, allowing for either a short or a long flag. If both are desired, use the Uint64P function.
func (*Parser) WithUint64P ¶ added in v1.6.0
WithUint64P returns a pouinter to a uint64 command line option, allowing for both a short and a long flag.
func (*Parser) WithUint64Var ¶ added in v1.5.0
WithUint64Var updates the Parser to recognize flag as a uint64 with the default value and description.
func (*Parser) WithUint64VarP ¶ added in v1.5.0
WithUint64Var updates the Parser to recognize short and long flag as a uint64 with the default value and description.
func (*Parser) WithUintP ¶ added in v1.6.0
WithUintP returns a pouinter to a uint command line option, allowing for both a short and a long flag.
func (*Parser) WithUintVar ¶ added in v1.5.0
WithUintVar updates the Parser to recognize flag as a uint with the default value and description.