Documentation
¶
Index ¶
- type Cmd
- type CmdSet
- func (c *CmdSet) Add(usage string, flags *flag.FlagSet, handler Handler, allowArgs bool) *Cmd
- func (c *CmdSet) HandleCmd(arguments []string, errorHandling flag.ErrorHandling) error
- func (c *CmdSet) Parse(arguments []string, errorHandling flag.ErrorHandling) (*Cmd, error)
- func (c *CmdSet) PrintUsage()
- func (c *CmdSet) Visit(f func(*Cmd))
- type Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdSet ¶
type CmdSet struct {
// contains filtered or unexported fields
}
A CmdSet contains a set of subcommands.
The zero value of CmdSet contains no commands. Use CmdSet.Add to add subcommands.
func (*CmdSet) Add ¶
Add adds a subcommand with specified usage string and flag set. The command name is derived from flags.Name. Use the allowArgs argument to specify wheather additional args should be allowed. For easy mapping from command to the relevant handler, supply a handler which will be added to the Cmd returned from Parse(). Returns the addded command.
Command names must be unique within a CommandSet. An attempt to define a command whose name is an emty string or whose name is already in use will cause a panic.
func (*CmdSet) HandleCmd ¶ added in v1.1.0
func (c *CmdSet) HandleCmd(arguments []string, errorHandling flag.ErrorHandling) error
HandleCmd is equivilant to Parse followed by calling the handler of the returned Cmd. If Parse fails, the reulting error is returned, otherwise the result from handle is returned.
func (*CmdSet) Parse ¶
Parse parses the subcommand from arguments[0] and its flags from arguments[1:] with the error handling specified by errorHandling. Returns the supplied Subcommand if a match was found.
Must be called after all subcommands are defined and before flags are accessed by the program. If arguments is nil, will default to `os.Args[1:]`.
func (*CmdSet) PrintUsage ¶
func (c *CmdSet) PrintUsage()
PrintUsage prints usage information to standard error.