Documentation
¶
Index ¶
- Variables
- type Beforer
- type Command
- func (cmd *Command) AddCommand(subCmd *Command) *Command
- func (cmd *Command) AddCommands(cmds []*Command) *Command
- func (cmd *Command) HelpString() string
- func (cmd *Command) Parse() ParsedCommand
- func (cmd *Command) ParseArgs(args []string) ParsedCommand
- func (cmd *Command) SetHelp(help string) *Command
- func (cmd *Command) SetShortHelp(help string) *Command
- func (cmd *Command) SetShortName(shortName string) *Command
- func (cmd *Command) WriteHelp(w io.Writer)
- type ParsedCommand
- type Runner
Constants ¶
This section is empty.
Variables ¶
var ErrHelp = fmt.Errorf("cli: help requested")
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
Name string
ShortName string
Help string
ShortHelp string
// contains filtered or unexported fields
}
func Build ¶
Build is like New, but it returns any errors instead of calling panic, at the expense of being harder to chain.
func New ¶
New creates a new Command with the provided name and config. The config must be a pointer to a configuration struct. Default values can be specified by simply setting them on the config struct.
New returns an Command pointer for further method chaining. If an error is encountered while building the options, such as a struct field having an unsupported type, New will panic. If you would like to have errors returned for handling, use Build instead.
func (*Command) AddCommand ¶
AddCommand registers another Command instance as a subcommand of this Command instance.
func (*Command) AddCommands ¶
AddCommands registers multiple Command instances as subcommands of this Command instance.
func (*Command) HelpString ¶
func (*Command) Parse ¶
func (cmd *Command) Parse() ParsedCommand
Parse is a convenience method for calling ParseArgs(os.Args)
func (*Command) ParseArgs ¶
func (cmd *Command) ParseArgs(args []string) ParsedCommand
ParseArgs parses using the passed-in args slice and OS-provided environment variables and returns a ParsedCommand instance which can be used for further method chaining.
If there are args remaining after parsing this Command' fields, subcommands will be parsed recursively. The returned ParsedCommand.Runner represents the command which was specified (if it has a Run method). If a Before method is implemented on the Command' config, this method will call it before recursing into any subcommand parsing.
func (*Command) SetShortHelp ¶
SetHelp configures the command short help string.
func (*Command) SetShortName ¶
SetShortName configures a short alias for the command.
type ParsedCommand ¶
func (ParsedCommand) Run ¶
func (po ParsedCommand) Run() error
Run calls the Run method of the Command config for the parsed command or, if an error occurred during parsing, prints the help text and returns that error instead. If help was requested, the error will flag.ErrHelp.
func (ParsedCommand) RunFatal ¶
func (po ParsedCommand) RunFatal()
RunFatal is like Run, except it automatically handles printing out any errors returned by the Run method of the underlying Command config, and exits with an appropriate status (1 if error, 0 otherwise).