Documentation ¶
Overview ¶
Package cmd provides (sub-)command functionality for command-line programs. This package works closely with the standard library flag package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultCmdMap = NewCmdMap()
DefaultCmdMap is the default command map.
Functions ¶
func PrintCmds ¶
func PrintCmds()
PrintCmds prints help text for all commands in the default command map to stderr.
Types ¶
type Cmd ¶
type Cmd struct { // Flag contains the command flag set. Flag *flag.FlagSet // Main is the function to run when the command is selected. Main func(cmd *Cmd, args []string) // Use contains the command usage string. Use string // Desc contains the command description. Desc string }
Cmd encapsulates a (sub-)command.
func Add ¶
Add adds a new command in the default command map.
The name parameter is the command name. However if this parameter contains a space or newline it is interpreted as described below. Consider:
NAME ARGUMENTS DESCRIPTION
Then the command name becomes "NAME", the command Use field becomes "NAME ARGUMENTS" and the command Desc field becomes "DESCRIPTION".
type CmdMap ¶
type CmdMap struct {
// contains filtered or unexported fields
}
CmdMap encapsulates a (sub-)command map.
func (*CmdMap) Add ¶
Add adds a new command in the command map.
The name parameter is the command name. However if this parameter contains a space or newline it is interpreted as described below. Consider:
NAME ARGUMENTS DESCRIPTION
Then the command name becomes "NAME", the command Use field becomes "NAME ARGUMENTS" and the command Desc field becomes "DESCRIPTION".