Documentation
¶
Overview ¶
Simple library for building CLI applications in Go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cli ¶
type Cli struct {
// contains filtered or unexported fields
}
func New ¶
func New() *Cli
New creates a new Cli struct for attaching commands, and flags to. There is no limit to how many of these you can create.
func (*Cli) AddFlag ¶
AddFlag takes a pointer to a Flag struct, and adds it to the Cli struct marking it as global. This flag will be passed down to every subsequent command added to the Cli struct.
func (*Cli) Command ¶
Command creates a new command for the Cli struct based on the name, and handler given. A pointer to the newly created Command is returned. The name of the command is typically what the user would type in to have the command run.
func (*Cli) Main ¶
Main specifies the main command to run should no initial command be found upon the first run of the application. This only takes a command handler.
func (*Cli) NilHandler ¶
func (c *Cli) NilHandler(handler commandHandler)
NilHandler specifies a handler to be used for commands which do not have a handler on them. This is useful if you have mulitple sub-commands that perform actions, but whose parent command does not.
type Command ¶
type Command struct {
// The pointer to the command's parent if it is a sub-command. Otherwise
// set to nil.
Parent *Command
// Name specifies the string the user inputs to execute the command. For
// sub-commands this will not be the full string including the parent's
// name, just the sub-command name itself.
Name string
// Args specifies the slice of arguments that are passed to the command.
Args args
// Flags specifies the flags that were set on the command.
Flags flags
// Commands specifies any sub-commands that the current command might have.
Commands commands
// Handler specifies the handler to call when the command is executed.
Handler commandHandler
// contains filtered or unexported fields
}
func (*Command) AddFlag ¶
AddFlag takes a pointer to a Flag struct, and adds it to the Cli struct. Similar to the AddFlag method on the Cli struct, only the flags are contained to the Command struct itself, and not passed down to the sub-commands.
func (*Command) Command ¶
Command creates a new command for the Command struct based on the nane, and handler given. Similar to the Command method on the Cli struct, only this creates a sub-command.
type Flag ¶
type Flag struct {
// Name specifies the name of the flag. This should be a string, and will
// be what is used to access the flag when passed to the command's handler.
Name string
// Short specifies the short version of a flag, for example '-h'.
Short string
// Long specifies the long version of a flag, for example '--help'.
Long string
// Argument specifies whether or not the flag takes an argument.
Argument bool
// If the flag takes an argument then the Value property will be set during
// parsing of the input arguments.
Value string
// Default specifies the default value the flag should be if no value is
// given to the flag. This is an interface, and before accessing the flag's
// value you should know what it's expected type should be.
Default interface{}
// Exclusive specifies whether or not a flag with a handler should be
// exclusive in its execution. Setting this to true means that no command
// will be executed if an exclusive flag, with a handler has been set on
// that command, and passed to that command.
//
// For example, the '--help' flag could be considered an exclusive flag.
// When passed to a command you do not want the command itself to be
// executed along with the '--help' flag.
Exclusive bool
// Handler specifies the handler for the flag should a flag be given to
// a command. This handler will be passed the flag itself, and the command
// on which the flag was passed.
Handler flagHandler
// contains filtered or unexported fields
}