Documentation
¶
Overview ¶
Package cmndr provides a lightweight means of constructing command-line interfaces for programs.
The goal of this package, is to provide something that is roughly comparable to github.com/spf13/cobra, but to provides something that is more lightweight, and relies on the Go standard library, as much as possible.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
type Cmd struct {
// The name of the command.
Name string
// A brief, single line description of the command.
Description string
// A *flag.FlagSet for registering command-line flags for the command.
Flags *flag.FlagSet
// Will be nil unless subcommands are registered with the AddCmd()
// method.
Commands map[string]*Cmd
// The function to run.
Run RunFunc
}
Cmd defines the structure of a command that can be run.
func New ¶
New is a convenience function for creating and returning a new *Cmd.
New will automatically add a "help" subcommand that, when called with no arguments, will print the help message for its parent command. If any arguments are provided to the "help" subcommand, only the first argument will be consulted, and it will print the help message for the specified subcommand.
Note, that the following two command-line calls are effectively the same:
$ my-command help <subcommand> $ my-command <subcommand> help
func (*Cmd) AddCmd ¶
AddCmd registers a subcommand.
AddCmd will panic if the given cmd's Name field is an empty string. If there is a subcommand already registered with the same name, it will be replaced.
func (*Cmd) Exec ¶
func (c *Cmd) Exec()
Exec parses the arguments provided on the command line. This is the method that should be called from the outer-most command (e.g. the "root" command).
It is essentially a short-hand invocation of
c.ExecArgs(os.Args[1:])
func (*Cmd) ExecArgs ¶
ExecArgs executes c.Run with the given arguments. If c.Run == nil, and no subcommand was provided as a positional argument, this method will print a usage message, and exit.
To customize the usage message that is printed, set c.Flags.Usage (refer to the documentation for flag.FlagSet).