Documentation
¶
Overview ¶
Package cliutils provides utilities for building command-line interfaces.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HelpRequested ¶
HelpRequested reads the argv and returns whether it contains one of `-h`, `--help`, in any position, or `help` as the first element in the vector. If this happens a subcommand should invoke its own help method to print help.
Types ¶
type Command ¶
type Command interface { // Help prints the help for the command on the stdout. Help(argv ...string) error // Main executes the command main function. Main(ctx context.Context, argv ...string) error }
Command is an rbmk command-line command.
type CommandWithSubCommands ¶
type CommandWithSubCommands struct {
// contains filtered or unexported fields
}
CommandWithSubCommands is a Command that contains subcommands.
It works as follows:
1. It automatically handles invocation with no arguments by printing help.
2. It handles `-h` and `--help` by printing help.
3. It handles `help [COMMAND...]` by printing help either for the command itself or for the selected subcommmand.
4. It handles `COMMAND...` by redirecting execution to the subcommand.
Construct using NewCommandWithSubCommands.
func NewCommandWithSubCommands ¶
func NewCommandWithSubCommands(name string, help string, commands map[string]Command) CommandWithSubCommands
NewCommandWithSubCommands constructs a CommandWithSubCommands.
The name argument contains the full name of this command (e.g., `rbmk run`).
The help argument contains the help string.
The commands argument contains the implemented subcommands.