Documentation ¶
Index ¶
- Variables
- func Execute(args []string, commandFns ...CommandFunction) error
- func MightExecute(args []string, commandFns ...CommandFunction) (bool, error)
- func MightExecuteWithErrorHandler(errHandler func(err error), args []string, commandFns ...CommandFunction) bool
- type Command
- type CommandFunction
- type CommandList
Constants ¶
This section is empty.
Variables ¶
var ErrUnrecognizedCommand = errors.New("No command executed")
Functions ¶
func Execute ¶
func Execute(args []string, commandFns ...CommandFunction) error
Execute takes an args array, and executes the appropriate command from the array of commandFunctions. If nil is passed as the args array, os.Args is used by default.
func MightExecute ¶
func MightExecute(args []string, commandFns ...CommandFunction) (bool, error)
MightExecute returns a boolean indicating if the command executed, and the error if it did (which can be nil if no error occurred) This is useful in a situation where you might execute a command, but don't mind if no command is executed, but want to catch an error if a command fails. This is coded as:
if did,err=commander.MightExecute(...); did&&nil!=err { panic(err) }
func MightExecuteWithErrorHandler ¶
func MightExecuteWithErrorHandler(errHandler func(err error), args []string, commandFns ...CommandFunction) bool
MightExecuteWithErrorHandler might execute any command, and has an associated error handler if an error occurs. It returns true if a command was executed, false otherwise.
Types ¶
type Command ¶
type Command struct { Command string Description string FlagSet *flag.FlagSet F func(args []string) error }
Command wraps together the short command name, the description for a command, the commands Flags and the function that will handle the command.
type CommandList ¶
type CommandList []*Command
func (CommandList) Len ¶
func (cl CommandList) Len() int
func (CommandList) Less ¶
func (cl CommandList) Less(i, j int) bool
func (CommandList) Swap ¶
func (cl CommandList) Swap(i, j int)