LibCppCmd v1.0 Beta 15
C++ Command Line Parsing Library
|
An ArgParam that represents an Option. More...
#include <Option.h>
Classes | |
struct | Definition |
This Definition is used to construct an Option. More... | |
Public Types | |
enum class | Style { Unix , Windows } |
The style of the Option to use. More... | |
Public Member Functions | |
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. | |
std::string | HelpInfo () const override |
Gets help info for the Option. | |
bool | IsSpecified () const override |
Indicates whether the Option has been specified. | |
bool | IsMandatory () const override |
Indicates whether the Option is mandatory. | |
bool | Populate (std::deque< std::string > &args) override |
Populates this Option from an argument queue. | |
bool | CanPopulate (const std::deque< std::string > &args) const override |
Determines if arguments can populate this Option. | |
std::size_t | Consumes (const std::deque< std::string > &args) const override |
Gets the number of arguments the Option consumes. | |
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. | |
An ArgParam that represents an Option.
A command line Option is an ArgParam that specifies an Option for the program. This is the most simple type of Option since it simply indicates whether it is specified when it is populated. 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, some programs have an Option that tells the program to produce vebose output. With the Unix Option style, either -v or –verbose could be used to specify such an Option. With the Windows Option style, either /v or /verbose could be used.
|
strong |
The style of the Option to use.
The style of Option determines the style of prefix used to specify and populate the Option at the command line. Unix style indicates that a - prefix should be used for short Option names and – for long Option names. Windows style indicates that a / prefix should be used for both short and long name Options.
CmdLine::Option::Option | ( | Definition | d | ) |
Constructs a new Option.
d | The definition used to create the Option. |
Param::InvalidDefinition | Doesn't satisfy invariants. |
|
overridevirtual |
Determines if arguments can populate this Option.
Accepts a reference to an argument queue (deque) and determines if the next argument in the queue can populate the Option.
args | The argument queue to evaluate. |
Implements CmdLine::ArgParam.
Reimplemented in CmdLine::ValueOption.
|
inlineoverridevirtual |
Gets the number of arguments the Option consumes.
An Option should consume exactly 1 argument.
args | The argument queue to evaluate. |
Implements CmdLine::ArgParam.
Reimplemented in CmdLine::ValueOption.
|
inlineoverridevirtual |
Gets the description of the Option.
The description of the Option is used for generating help.
Implements CmdLine::Param.
|
overridevirtual |
Gets help info for the Option.
The help info will include names (short and / or long) and description of the Option when generating help.
Implements CmdLine::Param.
Reimplemented in CmdLine::ValueOption.
|
inlineoverridevirtual |
Indicates whether the Option is mandatory.
The command line Parser uses this to determine if an Option must be specified at the command line for parsing to be successful. If a mandatory Option is not specified i.e. the correct command line argument necessary to populate the Option was not supplied, parsing will fail indicating the program was supplied with bad command line arguments.
Implements CmdLine::Param.
|
inlineoverridevirtual |
Indicates whether the Option has been specified.
An Option will only indicate it was specified if the Option has been successfully populated by a command line argument. The parser also uses this to determine if a mandatory Option has been specified.
Implements CmdLine::Param.
|
inline |
Gets the long name of the Option.
The long name of the Option is used to determine if the Option is specified at the command line. It is also used by the Parser to prevent duplicate Options from being added to to it. Finally, the long name is used to generate help info for the Option. This name will always represent the prefixed long name of the option unless the option has no long name, in which case this function will return an empty string.
|
overridevirtual |
Gets the name of the Option.
The name of the Option is used to determine if the Option is specified at the command line. It is also used by the Parser to prevent duplicate Options from being added to to it. Finally, the name is used to generate help info for the option. This name will always represent the prefixed short name of the Option unless the Option only has a long name, in which case this function will return the same value as the LongName() method.
Implements CmdLine::Param.
|
overridevirtual |
Populates this Option from an argument queue.
Accepts a reference to an argument queue (deque) and attempts to populate the Option from the next argument in the queue. Populating the Option marks it as specified. Successful population also consumes the argument from the queue that populated the Option.
args | The argument queue to populate the Option with. |
Implements CmdLine::ArgParam.
Reimplemented in CmdLine::ValueOption.
|
inline |
Sets the Option::Style of the Option.
Allows the program to change the Option::Style of the Option after it has been created. Alternatively, the Option::Style is set upon construction in the Option::Definition.
s | The Option::Style to set |