Cli Option¶
| Spice | |
|---|---|
CliOption<T> struct¶
A single command line option of a CLI parser. An option either writes the parsed value into a target variable or invokes a callback with it, depending on the mode it was constructed with.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a CLI option that writes the parsed value into a target variable
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
Primary name of the option (e.g. "--output") |
targetVariable |
T& |
Variable the parsed value is written to |
description |
string |
Help text describing the option |
ctor¶
| Spice | |
|---|---|
Construct a CLI option that writes the parsed value into a target variable
Parameters
| Name | Type | Description |
|---|---|---|
name |
const String& |
Primary name of the option (e.g. "--output") |
targetVariable |
T& |
Variable the parsed value is written to |
description |
const String& |
Help text describing the option |
ctor¶
| Spice | |
|---|---|
Construct a CLI option that invokes a callback with the parsed value
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
Primary name of the option (e.g. "--output") |
callback |
p(const T&) |
Callback to invoke with the parsed value |
description |
string |
Help text describing the option |
ctor¶
| Spice | |
|---|---|
Construct a CLI option that invokes a callback with the parsed value
Parameters
| Name | Type | Description |
|---|---|---|
name |
const String& |
Primary name of the option (e.g. "--output") |
callback |
p(const T&) |
Callback to invoke with the parsed value |
description |
const String& |
Help text describing the option |
Methods¶
getName¶
| Spice | |
|---|---|
Retrieve the primary name of the option
Returns: const String& — Name of the option
getDescription¶
| Spice | |
|---|---|
Retrieve the help text describing the option
Returns: const String& — Description of the option
addAlias¶
| Spice | |
|---|---|
Add an alternative name (alias) for the option
Parameters
| Name | Type | Description |
|---|---|---|
optionName |
string |
Alias to add |
addAlias¶
| Spice | |
|---|---|
Add an alternative name (alias) for the option
Parameters
| Name | Type | Description |
|---|---|---|
optionName |
const String& |
Alias to add |
getAliases¶
| Spice | |
|---|---|
Retrieve the list of aliases registered for the option
Returns: const Vector<String>& — Aliases of the option
allowMultipleValues¶
| Spice | |
|---|---|
Allow the option to take multiple values. All arguments after the option are taken as its values, up to the next option or the positional arguments, that are still missing. Each value is passed to the option separately.
acceptsMultipleValues¶
| Spice | |
|---|---|
Check whether the option can take multiple values
Returns: bool — true if the option can take multiple values, false otherwise
setTargetValue¶
| Spice | |
|---|---|
Write the given value into the option's target variable, if it is in set-value mode
Parameters
| Name | Type | Description |
|---|---|---|
value |
T& |
Value to write |
callCallback¶
| Spice | |
|---|---|
Invoke the option's callback with the given value, if it is in call-callback mode
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
Value to pass to the callback |
isPositional¶
| Spice | |
|---|---|
Check whether the option is positional, i.e. neither its name nor any alias starts with a dash
Returns: bool — true if the option is positional, false otherwise
printHelpItem¶
| Spice | |
|---|---|
Print the option's name, aliases and description as a single help entry