Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoDefaultCommand = errors.New("default command is not registered")
ErrNoDefaultCommand is used when the default default command isn't registered.
var Registry = make(commandRegistry)
Registry holds every command that gets saved in this global commands registry.
Functions ¶
func Exitf ¶
Exitf writes to os.Stderr and exits the process with a given code.
Shortcut for Errf(format); os.Exit(code).
func RegisterCommand ¶
RegisterCommand registers a command in the global command registry. ParseArguments looks into it to decide which command to dispatch.
Types ¶
type Args ¶
type Args []string
Args represents an ordered collection of command line argument.
func ParseArgs ¶
ParseArgs parses an OS-like command line input arguments.
If you need to create an arguments object out of a plain []string use Args{args}.
func (Args) CommandName ¶
CommandName extracts a command name out of all the arguments.
A command cannot start with --. We think of those arguments as options.
func (Args) First ¶ added in v0.3.0
First extracts the first argument, no matter if command or option.
func (Args) Get ¶ added in v0.10.0
Get checks if an --option has a value given.
If the option is not given, the default value is returned. There is currently no concept of optional arguments, as we haven't got the need.
func (Args) Has ¶ added in v0.3.0
Has tells whether the arguments contains a specific argument.
No distinction is made between arguments or options. Everything is matched as is.
type Command ¶
Command represents a command line action.
func DispatchCommand ¶
DispatchCommand dispatches the control to an registered command, if possible.
A command name is guessed out of the arguments. If the guessed name isn't registered, the dispatch will fall-back to the default command specified. It is expected that it is always registered. It is an error if its not.
type CommandRegistry ¶
CommandRegistry can be queried for the available commands and options.