Documentation
¶
Overview ¶
Package command runs physa's commands on Cobra. Cobra holds the tree of grouped commands, routes a command line to the command it names and parses every command's flags from its declaration: a command declares its flags once, on its own Cobra command, and its job gets only the positionals. Help prints the command's usage lines, its summary and its subcommands. --help anywhere after a command's name prints its help to stdout; -h is not a flag. A bad line, a bad flag included, prints that command's help to stderr and exits 2, with no error text of its own. Names match exactly: there are no aliases, no short flags, no prefix matching and no suggestions. Shell completion comes from the declarations through a hidden completion command. Drift ties every command's usage lines to its flags.
Index ¶
- Constants
- func Declare(c *cobra.Command, flags func(fs *pflag.FlagSet)) *cobra.Command
- func Drift(root *cobra.Command) []string
- func Execute(root *cobra.Command, args []string, stdout, stderr io.Writer) int
- func Help(c *cobra.Command, w io.Writer)
- func New(name, summary string, usage []string, run Run, subs ...*cobra.Command) *cobra.Command
- func Switch(fs *pflag.FlagSet, name string, on *bool, usage string)
- func Words(c *cobra.Command) []string
- type Resetter
- type Run
Constants ¶
const BadUsage = -1
BadUsage is what a Run returns for arguments it cannot parse. The command's help is then printed to stderr and the exit code is 2.
Variables ¶
This section is empty.
Functions ¶
func Declare ¶
Declare gives c, built by New, its flags: flags declares them on fs, and pflag parses them, so c's job gets only its positionals. flags runs again before every command line Execute runs, so each line starts from the defaults; a value it does not build afresh implements Resetter. A bad flag, a missing or invalid value, a shorthand such as -h and an empty string value print c's help to stderr and exit 2. flags must not declare help.
func Drift ¶
Drift returns one line per mismatch between a command's usage lines and its flags, for every command under root: a visible flag its usage lines don't name, or a --flag they name that it doesn't declare. A usage line that names one of the command's subcommands belongs to that subcommand.
func Execute ¶
Execute runs one command line against root and returns the process exit code: the command's own, 0 for --help, 2 for a bad line. The root's own help subcommand, if it has one, is its help command; without one, help is a word like any other and Cobra adds none.
func Help ¶
Help prints c's usage lines, its summary and its visible subcommands in the order they were declared. The output depends only on the tree.
func New ¶
New builds a command named name with its summary, its usage lines (each a full command line such as "physa map index [dir]"), the job run does (nil for a group with no bare job) and its subcommands, in order. It takes no flags until Declare gives it some, so any flag is a bad flag.