Documentation
¶
Index ¶
- type Cli
- type Command
- type Flag
- func (f Flag) GetFloat32() (float32, error)
- func (f Flag) GetFloat64() (float64, error)
- func (f Flag) GetInt() (int, error)
- func (f Flag) GetInt8() (int8, error)
- func (f Flag) GetInt16() (int16, error)
- func (f Flag) GetInt32() (int32, error)
- func (f Flag) GetInt64() (int64, error)
- func (f Flag) GetString() string
- func (f Flag) IsSet() bool
- type Flags
- func (f Flags) GetAll(name string) []Flag
- func (f Flags) GetFloat32(name string) (float32, error)
- func (f Flags) GetFloat64(name string) (float64, error)
- func (f Flags) GetInt(name string) (int, error)
- func (f Flags) GetInt8(name string) (int8, error)
- func (f Flags) GetInt16(name string) (int16, error)
- func (f Flags) GetInt32(name string) (int32, error)
- func (f Flags) GetInt64(name string) (int64, error)
- func (f Flags) GetString(name string) string
- func (f Flags) IsSet(name string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cli ¶
type Cli struct {
// contains filtered or unexported fields
}
The CLI program itself, this stores all of the program commands, and program level flags.
func (*Cli) AddFlag ¶
Add a flag to the entire program. This will be passed down to every other command in the program.
func (*Cli) MainCommand ¶ added in v1.1.0
Set the program's main command. This is invoked if no command can be found for running the program.
func (*Cli) Run ¶
Run the CLI program using the given slice of argument strings. This assumes that the programs name itself has been removed from the start of the input slice.
if err := c.Run(os.Args[1:]); err != nil {
}
The errors returned from this method will be about unknown program commands or unknown flags.
type Command ¶
type Command struct {
// The name of the command that will be passed to the program for command
// invocation.
Name string
// The arguments passed to the individual command. Starting out this will
// be empty, and will be populated once the command's flags have been parsed
// from the programs input arguments.
Args args
// The flags that have been added to the command. Starting out this will be
// empty much like the command arguments. During parsing the command flags
// will be set accordingly, whether they be value flags or boolean flags.
Flags Flags
// contains filtered or unexported fields
}
A command for your program, this can either be a main command, regular command or a sub-command.
func (*Command) AddFlag ¶
Add a flag to the current command. If the given flag is a global program flag, then set it on each of the command's sub-commands.
type Flag ¶
type Flag struct {
// The name of the flag. This is used to retrieve the flag from the flags
// type that stores either the program's flags, or a command's flags.
Name string
// The short version of the flag. Typically a single letter value preprended
// with a single '-'.
Short string
// The long version of the flag. Typically a hyphenated string value
// prepended with a '--'.
Long string
// Whether the flag takes an argument. If set to true, then the flag's
// argument will be parsed from the input strings. Listed below are the
// three valid ways of specifying a flag's value:
//
// -f arg
// --flag arg
// --flag=arg
Argument bool
// The default value of the flag if no value is given to the flag itself
// during program program invocation.
Default interface{}
// The handler to invoke whenever the flag is set.
Handler flagHandler
// If a flag is exclusive then the flag's handler will be invoked, and the
// flag's command will not be invoked.
Exclusive bool
// contains filtered or unexported fields
}
A flag for your program, or for the program's individual command.
func (Flag) GetFloat32 ¶ added in v1.1.0
Attempt to parse the underlying flag string value to a float32 type.
func (Flag) GetFloat64 ¶ added in v1.1.0
Attempt to parse the underlying flag string value to a float64 type.
func (Flag) GetInt ¶ added in v1.1.0
Attempt to parse the underlying flag string value to an int type.
func (Flag) GetInt8 ¶ added in v1.1.0
Attempt to parse the underlying flag string value to an int8 type.
func (Flag) GetInt16 ¶ added in v1.1.0
Attempt to parse the underlying flag string value to an int16 type.
func (Flag) GetInt32 ¶ added in v1.1.0
Attempt to parse the underlying flag string value to an int32 type.
func (Flag) GetInt64 ¶ added in v1.1.0
Attempt to parse the underlying flag string value to an int64 type.
type Flags ¶ added in v1.1.0
type Flags struct {
// contains filtered or unexported fields
}
func (Flags) GetFloat32 ¶ added in v1.1.0
Attempt to parse the first flag's value as a float32 for the given flag name.
func (Flags) GetFloat64 ¶ added in v1.1.0
Attempt to parse the first flag's value as a float64 for the given flag name.
func (Flags) GetInt ¶ added in v1.1.0
Attempt to parse the first flag's value as an int for the given flag name.
func (Flags) GetInt8 ¶ added in v1.1.0
Attempt to parse the first flag's value as an int8 for the given flag name.
func (Flags) GetInt16 ¶ added in v1.1.0
Attempt to parse the first flag's value as an int16 for the given flag name.
func (Flags) GetInt32 ¶ added in v1.1.0
Attempt to parse the first flag's value as an int32 for the given flag name.
func (Flags) GetInt64 ¶ added in v1.1.0
Attempt to parse the first flag's value as an int64 for the given flag name.