|
LibCppCmdLine v1.0
A cross-platform C++ library for parsing command line arguments
|
Provides parameters for ValueOption values. More...
#include <OptionParam.h>
Classes | |
| struct | Definition |
| This definition is used to construct an OptionParam. More... | |
Public Member Functions | |
| OptionParam (Definition definition) | |
| Constructs a new OptionParam. | |
| std::string | Name () const override |
| Gets the name of the Param. | |
| std::string | Description () const override |
| Gets the description of the Param. | |
| std::string | HelpInfo () const override |
| Gets help information for the Param. | |
| bool | IsSpecified () const override |
| Indicates whether the OptionParam has been specified. | |
| bool | IsMandatory () const override |
| Indicates whether the Param is mandatory. | |
| std::string | Value () const |
| Gets the value the OptionParam was populated with. | |
| bool | Populate (NameValuePair p) |
| Populates the OptionParam from a NameValuePair. | |
| bool | CanPopulate (NameValuePair p) const |
| Checks if the NameValuePair can populate OptionParam. | |
| Public Member Functions inherited from CmdLine::Param | |
| virtual | ~Param ()=default |
| Destructs a Param. | |
Provides parameters for ValueOption values.
An OptionParam provides a way for a program to capture specific values passed to a ValueOption. Option parameters can be added to value options for this purpose. This is useful for value options have a specific list of possible values when the program needs to check that one or more of those possible values was specified. The name of the option parameter defines the possible option value. If the value passed to the ValueOption at the command line is a NameValuePair, the the option parameter will not only indicate that the name was specified as a possible value, it will also have its own value (the value of the NameValuePair). For example, assume a ValueOption "--print" instructs a program to print metadata values for a song. Assume the possible values for the "--print" ValueOption are "song", "artist", and "album". In this case you would add three option parameters to the "--print" ValueOption. Assume then that the user specifies "--print song" at the command line. The option parameter "song" would be specified but have no value of its own. Now assume the same program has an "--edit" ValueOption to change those same metadata properties. If the users specified "--edit 'song=Happy Birthday'", the "song" option parameter would be specified and have the value "Happy Birthday".
| CmdLine::OptionParam::OptionParam | ( | Definition | definition | ) |
Constructs a new OptionParam.
| definition | The definition to construct the OptionParam. |
| Param::InvalidDefinition | Doesn't satisfy invariants. |
| bool CmdLine::OptionParam::CanPopulate | ( | NameValuePair | p | ) | const |
Checks if the NameValuePair can populate OptionParam.
| p | The NameValuePair to evaluate. |
|
inlineoverridevirtual |
Gets the description of the Param.
The description of the Param is used for generating help.
Implements CmdLine::Param.
|
overridevirtual |
Gets help information for the Param.
The help info will include the Name() and Description() of the parameter when generating help.
Implements CmdLine::Param.
|
inlineoverridevirtual |
Indicates whether the Param is mandatory.
The command line Parser uses this to determine if a parameter must be specified at the command line for parsing to be successful. If a mandatory parameter is not specified, parsing will fail indicating the program was supplied with bad command line arguments.
Implements CmdLine::Param.
|
inlineoverridevirtual |
Indicates whether the OptionParam has been specified.
An OptionParam will only indicate it was specified if the parameter has been successfully populated by an OptionValue. The Parser also uses this to determine if a mandatory OptionParam has been specified.
Implements CmdLine::Param.
|
inlineoverridevirtual |
Gets the name of the Param.
The name of the Param is used for generating usage and help.
Implements CmdLine::Param.
| bool CmdLine::OptionParam::Populate | ( | NameValuePair | p | ) |
Populates the OptionParam from a NameValuePair.
An OptionParam is populated from a NameValuePair that represents an argument (value) that was passed to the ValueOption at the command line. If the NameValuePair itself does not specifiy a value, population will only mark the parameter as specified, otherwise it will both specify the parameter and populate its value.
| p | The NameValuePair to populate the OptionParam with. |
|
inline |
Gets the value the OptionParam was populated with.
The value of an OptionParam is the value of a NameValuePair passed to the ValueOption at the command line. If just a name was passed, the value will be an empty string.