Struct ProgramCommands
You can configure a ProgramCommands
object with a number of Command
s and then use it to parse
an list of command line arguments
struct ProgramCommands(_Commands...)
if (_Commands .length > 0);
The object will generate its member variables from the Command
s you pass in, for e.g.
auto commands = ProgramCommands!(Command!"one", Command!"two");
commands .one // generated variable
commands .two // generated variable
After you parse command line arguments, the commands that are encountered on the command line become "activated" and can be checked by casting them to a boolean, i.e.
commands .parse(["two"]);
if (commands .one) {} // will be false
if (commands .two) {} // will be true
You can also assign "handler" to a command and use the executeHandlers
function to call them for the
commands that were activated.
Fields
Name | Type | Description |
---|---|---|
options
|
Commands[0] | The ProgramOptions that are associated with this command if any was passed in. If no ProgramOptions
where passed as an argument then this aliases to a Void pseudo type.
|
Methods
Name | Description |
---|---|
executeHandlers
|
If any of the Command s have any handlers specified. Then those will be called
in order of appearance on the command line by calling this function
|
helpText
|
Returns a string that represents a block of text that can be output to stdout to display a help message |
parse
|
Parses the command line arguments according to the set of Commands s that are passed in.
|
toString
|
Returns a string that is a stringified object of keys and values denoting commands and their values and options (if present) |
Parameters
Name | Description |
---|---|
_Commands | 1 or more Command objects, each representing one command line argument. The first
argument may be a ProgramOptions type if you want the command to have a set of options
that it may handle |