Cli Subcommand¶
| Spice | |
|---|---|
CliSubcommand struct¶
A subcommand of a CLI parser. It groups options, flags and nested subcommands under a name and is responsible for parsing the slice of arguments that belongs to it. The root of a CliParser is itself a CliSubcommand.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a subcommand
Parameters
| Name | Type | Description |
|---|---|---|
parent |
CliSubcommand* |
Parent subcommand, or nil for the root subcommand |
versionString |
const String& |
Version string inherited from the parent |
name |
const String& |
Name of the subcommand |
description |
const String& |
Description of the subcommand shown in the help output (default: String("")) |
Methods¶
parse¶
| Spice | |
|---|---|
Parse the arguments belonging to this subcommand, dispatching to nested subcommands as needed
Parameters
| Name | Type | Description |
|---|---|---|
argc |
unsigned int |
Number of arguments |
argv |
string[] |
Array of argument strings |
layer |
int |
Index of the first argument that belongs to this subcommand (default: 1) |
Returns: int — Exit code of the parse run
getName¶
| Spice | |
|---|---|
Retrieve the name of the subcommand
Returns: const String& — Name of the subcommand
getDescription¶
| Spice | |
|---|---|
Retrieve the description of the subcommand
Returns: const String& — Description of the subcommand
setVersion¶
| Spice | |
|---|---|
Set the version string reported by the subcommand
Parameters
| Name | Type | Description |
|---|---|---|
versionString |
const String& |
Version string to report |
setFooter¶
| Spice | |
|---|---|
Set the footer text shown at the bottom of the subcommand's help output
Parameters
| Name | Type | Description |
|---|---|---|
footerString |
const String& |
Footer text |
setCallback¶
| Spice | |
|---|---|
Set the callback invoked when this subcommand is selected without a nested subcommand
Parameters
| Name | Type | Description |
|---|---|---|
callback |
p() |
Callback to invoke |
allowUnknownOptions¶
| Spice | |
|---|---|
Allow unknown options on this subcommand and all of its nested subcommands
addAlias¶
| Spice | |
|---|---|
Add an alternative name (alias) for the subcommand
Parameters
| Name | Type | Description |
|---|---|---|
subCommand |
string |
Alias to add |
addAlias¶
| Spice | |
|---|---|
Add an alternative name (alias) for the subcommand
Parameters
| Name | Type | Description |
|---|---|---|
subCommand |
const String& |
Alias to add |
addSubcommand¶
| Spice | |
|---|---|
Register a nested subcommand
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
Name of the subcommand |
description |
string |
Description of the subcommand |
Returns: CliSubcommand& — Reference to the newly created subcommand
addSubcommand¶
| Spice | |
|---|---|
Register a nested subcommand
Parameters
| Name | Type | Description |
|---|---|---|
name |
const String& |
Name of the subcommand |
description |
const String& |
Description of the subcommand |
Returns: CliSubcommand& — Reference to the newly created subcommand
addOption¶
| Spice | |
|---|---|
Register a string option on the subcommand. If the name does not start with a dash, the option is treated as a positional argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the option |
output |
TargetVarOrCallbackString |
Target variable or callback receiving the parsed value |
description |
StrOrConstStrObjRef |
Description of the option |
Returns: CliOption<string>& — Reference to the newly created option
addOption¶
| Spice | |
|---|---|
Register a String option on the subcommand. If the name does not start with a dash, the option is treated as a positional argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the option |
output |
TargetVarOrCallbackStringObj |
Target variable or callback receiving the parsed value |
description |
StrOrConstStrObjRef |
Description of the option |
Returns: CliOption<String>& — Reference to the newly created option
addOption¶
| Spice | |
|---|---|
Register an int option on the subcommand. If the name does not start with a dash, the option is treated as a positional argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the option |
output |
TargetVarOrCallbackInt |
Target variable or callback receiving the parsed value |
description |
StrOrConstStrObjRef |
Description of the option |
Returns: CliOption<int>& — Reference to the newly created option
addOption¶
| Spice | |
|---|---|
Register a FilePath option on the subcommand. If the name does not start with a dash, the option is treated as a positional argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the option |
output |
TargetVarOrCallbackFilePath |
Target variable or callback receiving the parsed value |
description |
StrOrConstStrObjRef |
Description of the option |
Returns: CliOption<FilePath>& — Reference to the newly created option
addFlag¶
| Spice | |
|---|---|
Register a boolean flag on the subcommand
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the flag |
output |
TargetVarOrCallbackBool |
Target variable set to true, or callback invoked, when the flag is present |
description |
StrOrConstStrObjRef |
Description of the flag |
Returns: CliOption<bool>& — Reference to the newly created flag
printHelpItem¶
| Spice | |
|---|---|
Print the subcommand's name, aliases and description as a single help entry