Documentation ¶
Overview ¶
Package subcommands allows you to easily implement a simple CLI with well-defined and distinct subcommands.
The implementation is pretty naive, but it is sufficient to implement a simple command.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(cmd Subcommand)
Register adds a new subcommand to those which are available.
Types ¶
type BashCompletion ¶ added in v0.8.0
type BashCompletion struct { // We embed the NoFlags option, because we accept no // command-line flags. NoFlags }
BashCompletion is a structure which implements the built-in "bash-completion" subcommand.
func (*BashCompletion) Execute ¶ added in v0.8.0
func (bc *BashCompletion) Execute(args []string) int
Execute the command.
func (*BashCompletion) Info ¶ added in v0.8.0
func (bc *BashCompletion) Info() (string, string)
Info returns the name of this subcommand, along with a one-line synopsis.
type CommandList ¶ added in v0.7.0
type CommandList struct { // We embed the NoFlags option, because we accept no // command-line flags. NoFlags }
CommandList is a structure which implements the built-in "commands" subcommand
func (*CommandList) Execute ¶ added in v0.7.0
func (c *CommandList) Execute(args []string) int
Execute the command.
func (*CommandList) Info ¶ added in v0.7.0
func (c *CommandList) Info() (string, string)
Info returns the name of this subcommand, along with a one-line synopsis.
type Help ¶
type Help struct { // We embed the NoFlags option, because we accept no // command-line flags. NoFlags }
Help is a structure which implements the built-in help subcommand
type NoFlags ¶
type NoFlags struct { }
NoFlags is a helper method which allows you to define sub-commands which take no flags.
You still need to define `Info`, and `Execute()`, but this saves a little needless typing.
type Subcommand ¶
type Subcommand interface { // Arguments sets up any required arguments. Arguments(f *flag.FlagSet) // Info is designed to returns the name, and brief // description of the command. Info() (string, string) // The function is invoked if this subcommand is invoked. // // The arguments are any non-flag arguments passed to the // subcommand, and the return value can be used as your // exit-code. Execute(args []string) int }
Subcommand is the interface which subcommands must implement.
In brief a sub-command has a name, a function to invoke it, and the ability to define command-line flags which are specific to it.