Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// FlagSet is the flag set for the command.
FlagSet *flag.FlagSet
// Aliases for the command name.
Aliases []string
// Handler is the function that is invoked to handle this command.
//
// The error types *UsageError and *ExitCodeError have special meaning, consult their docs for
// details.
Handler func(args []string) error
// A flagSet.Usage function to invoke when e.g. the -h flag is specified. If nil, a default one
// is used.
UsageFunc func()
}
Command is a subcommand handler and its associated flag set.
type Commander ¶
type Commander []*Command
Commander represents a command with a list of subcommands.
func (Commander) Run ¶
Run runs a subcommand of the command described by the input flagSet (e.g. flag.CommandLine).
cmdName and usageText should describe your command, not the subcommand. Consult "go help" for inspiration when writing your own usageText.
A special "help" command is registered automatically, which acts the same as the `-h` flag.
type ExitCodeError ¶
type ExitCodeError struct {
// Err is the error to log when exiting.
Err error
// ExitCode is the exit status code to use in the call to os.Exit.
ExitCode int
}
ExitCodeError is an error type that subcommands can return in order to specify the exact exit code.
func (*ExitCodeError) Error ¶
func (e *ExitCodeError) Error() string
Error implements the error interface.
type UsageError ¶
type UsageError struct {
// Err is the error to log when exiting.
Err error
}
UsageError is an error type that subcommands can return in order to signal that a usage error has occurred.
func (*UsageError) Error ¶
func (e *UsageError) Error() string
Error implements the error interface.