Cli Parser¶
| Spice | |
|---|---|
CliParser struct¶
A command line argument parser. It owns the root subcommand and forwards configuration and parsing to it, so options, flags and subcommands can be registered before parsing the actual arguments.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a CLI parser for an application
Parameters
| Name | Type | Description |
|---|---|---|
appName |
string |
Name of the application |
appDescription |
string |
Description of the application shown in the help output (default: "") |
ctor¶
| Spice | |
|---|---|
Construct a CLI parser for an application
Parameters
| Name | Type | Description |
|---|---|---|
appName |
const String& |
Name of the application |
appDescription |
const String& |
Description of the application shown in the help output (default: String("")) |
Methods¶
setVersion¶
| Spice | |
|---|---|
Set the version string reported by the application
Parameters
| Name | Type | Description |
|---|---|---|
versionString |
string |
Version string to report |
setVersion¶
| Spice | |
|---|---|
Set the version string reported by the application
Parameters
| Name | Type | Description |
|---|---|---|
versionString |
const String& |
Version string to report |
setFooter¶
| Spice | |
|---|---|
Set the footer text shown at the bottom of the help output
Parameters
| Name | Type | Description |
|---|---|---|
footer |
string |
Footer text |
setFooter¶
| Spice | |
|---|---|
Set the footer text shown at the bottom of the help output
Parameters
| Name | Type | Description |
|---|---|---|
footer |
const String& |
Footer text |
setRootCallback¶
| Spice | |
|---|---|
Set the callback invoked when the application is run without a subcommand
Parameters
| Name | Type | Description |
|---|---|---|
callback |
p() |
Callback to invoke |
allowUnknownOptions¶
| Spice | |
|---|---|
Allow unknown options to be passed without aborting parsing with an error
addSubcommand¶
| Spice | |
|---|---|
Register a subcommand on the application
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the subcommand |
description |
StrOrConstStrObjRef |
Description of the subcommand |
Returns: CliSubcommand& — Reference to the newly created subcommand
addOption¶
| Spice | |
|---|---|
Register an option that writes its parsed value into a target variable
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the option |
targetVariable |
T& |
Variable the parsed value is written to |
description |
StrOrConstStrObjRef |
Description of the option |
Returns: CliOption<T>& — Reference to the newly created option
addOption¶
| Spice | |
|---|---|
Register an option that invokes a callback with its parsed value
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the option |
callback |
p(const T&) |
Callback to invoke with the parsed value |
description |
StrOrConstStrObjRef |
Description of the option |
Returns: CliOption<T>& — Reference to the newly created option
addFlag¶
| Spice | |
|---|---|
Register a boolean flag that writes its presence into a target variable
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the flag |
targetVariable |
bool& |
Variable set to true when the flag is present |
description |
StrOrConstStrObjRef |
Description of the flag |
Returns: CliOption<bool>& — Reference to the newly created flag
addFlag¶
| Spice | |
|---|---|
Register a boolean flag that invokes a callback when present
Parameters
| Name | Type | Description |
|---|---|---|
name |
StrOrConstStrObjRef |
Name of the flag |
callback |
p(const bool&) |
Callback to invoke when the flag is present |
description |
StrOrConstStrObjRef |
Description of the flag |
Returns: CliOption<bool>& — Reference to the newly created flag
parse¶
| Spice | |
|---|---|
Parse the given command line arguments
Parameters
| Name | Type | Description |
|---|---|---|
argc |
unsigned int |
Number of arguments |
argv |
string[] |
Array of argument strings |
Returns: int — Exit code of the parse run