LibCppCmd v1.0 Beta 15
C++ Command Line Parsing Library
|
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 OptionParam. | |
std::string | Description () const override |
Getst the description of the OptionParam. | |
std::string | HelpInfo () const override |
Gets help info for the OptionParam. | |
bool | IsSpecified () const override |
Indicates whether the OptionParam has been specified. | |
bool | IsMandatory () const override |
Indicates whether the OptionParam 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. OptionParams can be added to ValueOptions for this purpose. This is useful for ValueOptions that 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 OptionParam defines the possible Option value. If the value passed to the ValueOption at the command line is a NameValuePair, the the OptionParam 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 OptionParams to the "--print" ValueOption. Assume then that the user specifies "--print song" at the command line. The OptionParam "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" OptionParam 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. |
Parame: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 |
Getst the description of the OptionParam.
The description of the OptionParam is used for generating help.
Implements CmdLine::Param.
|
overridevirtual |
Gets help info for the OptionParam.
The help info will include the name and description of the OptionParam when generating help.
Implements CmdLine::Param.
|
inlineoverridevirtual |
Indicates whether the OptionParam is mandatory.
The command line Parser uses this to determine if an OptionParam must be specified at the command line for parsing to be successful. If a mandatory OptionParam 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 OptionParam 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 OptionParam.
The name of the OptionParam 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 OptionParam as specified, otherwise it will both specify the OptionParam 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.