LibCppCmd v1.0 Beta 15
C++ Command Line Parsing Library
|
A command line Option that is populated with values. More...
#include <ValueOption.h>
Classes | |
struct | Definition |
This definition is used to construct a ValueOption. More... | |
class | DuplicateOptionParam |
An exception thrown for adding duplicate OptionParams. More... | |
class | NullOptionParam |
An exception thrown for adding null OptionParam. More... | |
Public Member Functions | |
ValueOption (Definition d) | |
Constructs a new ValueOption. | |
bool | Populate (std::deque< std::string > &args) override |
Populates this ValueOption from an argument queue. | |
bool | CanPopulate (const std::deque< std::string > &args) const override |
Determines if arguments can populate this ValueOption. | |
std::size_t | Consumes (const std::deque< std::string > &args) const override |
Gets the number of arguments the ValueOption consumes. | |
std::string | HelpInfo () const override |
Gets help info for the ValueOption. | |
std::vector< std::string > | Values () const |
Gets the values the ValueOption is populated with. | |
void | Add (OptionParam *p) |
Adds the specified OptionParam to the ValueOption. | |
Public Member Functions inherited from CmdLine::Option | |
Option (Definition d) | |
Constructs a new Option. | |
std::string | Name () const override |
Gets the name of the Option. | |
std::string | Description () const override |
Gets the description of the Option. | |
bool | IsSpecified () const override |
Indicates whether the Option has been specified. | |
bool | IsMandatory () const override |
Indicates whether the Option is mandatory. | |
void | Set (Style s) |
Sets the Option::Style of the Option. | |
std::string | LongName () const |
Gets the long name of the Option. | |
Public Member Functions inherited from CmdLine::ArgParam | |
virtual | ~ArgParam ()=default |
Destructs an ArgParam. | |
Public Member Functions inherited from CmdLine::Param | |
virtual | ~Param ()=default |
Destructs a Param. | |
Additional Inherited Members | |
Public Types inherited from CmdLine::Option | |
enum class | Style { Unix , Windows } |
The style of the Option to use. More... | |
A command line Option that is populated with values.
A command line ValueOption is an ArgParam that not only specifies an Option for the program but also captures one or more values associated with that option. Command line arguments that populate and specify Options begin with an Option prefix followed by a short name (single character) or long name (multiple characters). What prefix is used depends on the Option::Style used (Unix or Windows). For instance, a media program might have an Option that prints song metadata. Wit the Unix Option style, either "-p" or "--print" could be used to specify such an Option. With the Windows Option::Style, either "/p" or "/print" could be used. Using that same example, to print the album of a song using a hypothetical "--print" Option, one might specify "--print album" at the command line. In this case, not only would the "--print" Option be specified, but it would be populated with the value "album". Assuming there was a specific list of possible values for "--print", ValueOption supports adding OptionParams which are specified by a specific Option value. For instance, one might add OptionParams for "song", "album", "artist", etc. For an Option that sets such a value, you could have an "--edit" option. For example, "--edit 'artist=The Beatles'". In this case the value is a NameValuePair and an "artist" OptionParam could extract the value from the pair. Finally, a ValueOption may be specified multiple times to populate it with multiple values.
CmdLine::ValueOption::ValueOption | ( | Definition | d | ) |
Constructs a new ValueOption.
d | The definition used to create the Option. |
Param::InvalidDefinition | Doesn't satisfy invariants. |
void CmdLine::ValueOption::Add | ( | OptionParam * | p | ) |
Adds the specified OptionParam to the ValueOption.
Each OptionParam pointer added to the ValueOption can be populated by a ValueOption value (or name-value pair) that matches the OptionParam's name. Adding OptionParams to the ValueOption can be a way of constraining the ValueOption to a list of possible values that will indicate whether or not they were specified.
p | The OptionParam pointer to add |
DuplicateOptionParam | Tried to add duplicate OptionParam. |
|
overridevirtual |
Determines if arguments can populate this ValueOption.
Accepts a reference to an argument queue (deque) and determines if the next two arguments in the queue can populate the ValueOption.
args | The arguments queue to evaluate. |
Reimplemented from CmdLine::Option.
|
inlineoverridevirtual |
Gets the number of arguments the ValueOption consumes.
A ValueOption should consume exatly 2 arguments.
args | The argument queue to evaluate. |
Reimplemented from CmdLine::Option.
|
overridevirtual |
Gets help info for the ValueOption.
The help info will include names (short and / or long) and description of the Option when generating help. It will also include the help info of any OptionParams that were added to the ValueOption.
Reimplemented from CmdLine::Option.
|
overridevirtual |
Populates this ValueOption from an argument queue.
Accepts a reference to an argument queue (deque) and attempts to populate the ValueOption from the next two arguments in the queue. Populating the ValueOption marks it as specified. Successful population also consumes the two arguments from the queue that populated the ValueOption.
args | The argument queue to populate the Option with. |
Reimplemented from CmdLine::Option.
|
inline |
Gets the values the ValueOption is populated with.
ValueOptions are populated with the command line argument that is passed to the ValueOtion by the user. This argument can either be a single value or a NameValuePair.