Documentation ¶
Overview ¶
A CLI Parser for Go
Overview ¶
Commando is a cli parser that handles nested commands, usage / help output, flags, and output _formatting_ for you.
Define a root command, and attach subcommands to it. Tell your new commands what function to execute, and that's it.
Why ¶
Because I don't like the UX of Flags. The goal here is a clean API to define complex cli programs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintFields ¶
PrintFields is a wrapper for an IO Writer / Formatter. Using commando.PrintFields evenly spaces output into columns.
Types ¶
type Command ¶
type Command struct { Name string // Name of command, typically how a command is called from the cli. Description string // A Description of the command, printed in usage. Options map[string]*Option // A map of the flags attached to this command, they are looked up by their name. Children map[string]*Command // A map of all the subcommands, looked up by their name. Parent *Command // A pointer to the command's parent. not set in root command. Execute func() // The function to run when executing a command. }
Command is the base type for all commands.
func (*Command) AddSubCommand ¶
AddSubcommand attaches a command to a parent, as well as sets the parent property on the child command. Commands can be limitlessly nested (though, I don't recommend it).
type Option ¶
type Option struct { Name string // Name of Option, its name is used to retrieve its value. Description string // A Description of the option, used when printing usage. Flags []string // The flags associated with the option. Value interface{} // Where the value of a given flag is scanned into. Present bool // Used to determine whether or not a flag is present, typically for a bool type flag. Required bool // If a flag is required and not present, usage for owning command is printed. }
Option is the type for flag options like "-p" or "--path"