A compact command line argument parser. More...
#include <CommandLine.hpp>
Public Member Functions | |
CommandLine (CommandLineStyle style_=CommandLineStyle::Detect) | |
Create a command line parser with the specified style. More... | |
CommandLine (const CommandLine &)=default | |
Create a command line parser by copying the supplied parser. More... | |
CommandLine (CommandLine &&) noexcept=default | |
Create a command line parser by moving the supplied parser. More... | |
std::string | getFinalValue (size_t index=0) const |
Get the final value with the specified index as a string or throw if no final value is available. More... | |
double | getFinalValueAsDouble (size_t index=0) const |
Get the final value as a double or throw if no final value is available. More... | |
double | getFinalValueAsDoubleOrDefault (double defaultValue, size_t index=0) const |
Get the final value as a double or return the supplied default if no final value is available. More... | |
float | getFinalValueAsFloat (size_t index=0) const |
Get the final value as a float or throw if no final value is available. More... | |
float | getFinalValueAsFloatOrDefault (float defaultValue, size_t index=0) const |
Get the final value as a float or return the supplied default if no final value is available. More... | |
size_t | getFinalValueCount () const |
Get the number of final values available. More... | |
std::string | getFinalValueOrDefault (const std::string &defaultValue, size_t index=0) const |
Get the final value as a string or return the supplied default if no final value is available. More... | |
std::string | getHelpText (size_t indent, size_t totalWidth, CommandLineStyle styleOverride=CommandLineStyle::Detect) const |
Get the help text. More... | |
std::string | getOption (KeyT key) const |
Get the specified option value as a UTF-8 string. More... | |
double | getOptionAsDouble (KeyT key) const |
Get the specified option value as a double. More... | |
double | getOptionAsDoubleOrDefault (KeyT key, double defaultValue) const |
Get the specified option value as a double or return the supplied value if there is no such option. More... | |
float | getOptionAsFloat (KeyT key) const |
Get the specified option value as a float. More... | |
float | getOptionAsFloatOrDefault (KeyT key, float defaultValue) const |
Get the specified option value as a float or return the supplied value if there is no such option. More... | |
int | getOptionAsInt (KeyT key) const |
Get the specified option value as a signed integer value. More... | |
int | getOptionAsIntOrDefault (KeyT key, int defaultValue) const |
Get the specified option value as a signed int, or the specified default if there is no such option. More... | |
long long | getOptionAsLong (KeyT key) const |
Get the specified option value as a signed long long value. More... | |
long long | getOptionAsLongOrDefault (KeyT key, long long defaultValue) const |
Get the specified option value as a signed long long, or the specified default if there is no such option. More... | |
short | getOptionAsShort (KeyT key) const |
Get the specified option value as a signed short value. More... | |
short | getOptionAsShortOrDefault (KeyT key, short defaultValue) const |
Get the specified option value as a signed short, or the specified default if there is no such option. More... | |
unsigned int | getOptionAsUnsignedInt (KeyT key) const |
Get the specified option value as an unsigned integer value. More... | |
unsigned int | getOptionAsUnsignedIntOrDefault (KeyT key, unsigned int defaultValue) const |
Get the specified option value as an unsigned int, or the specified default if there is no such option. More... | |
unsigned long long | getOptionAsUnsignedLong (KeyT key) const |
Get the specified option value as an unsigned long long value. More... | |
unsigned long long | getOptionAsUnsignedLongOrDefault (KeyT key, unsigned long long defaultValue) const |
Get the specified option value as an unsigned long long, or the specified default if there is no such option. More... | |
unsigned short | getOptionAsUnsignedShort (KeyT key) const |
Get the specified option value as an unsigned short value. More... | |
unsigned short | getOptionAsUnsignedShortOrDefault (KeyT key, unsigned short defaultValue) const |
Get the specified option value as an unsigned short, or the specified default if there is no such option. More... | |
std::string | getOptionOrDefault (KeyT key, std::string defaultValue) const |
Get the specified option value as a string, or the specified default if there is no such option. More... | |
bool | hasOption (KeyT key) const |
Does the command line option set have the specified option? More... | |
CommandLine & | operator= (const CommandLine &)=default |
Assign the current command line parser to a copy of the supplied parser. More... | |
CommandLine & | operator= (CommandLine &&) noexcept=default |
Assign the current command line parser by moving the contents of the supplied parser. More... | |
void | parse (int argc, char *argv[], bool ignoreFirst) |
Parse the input arguments. More... | |
void | parse (int argc, const char *argv[], bool ignoreFirst) |
Parse the input arguments. More... | |
void | parse (const std::vector< std::string > &args, bool ignoreFirst) |
Parse the input arguments, which are supplied as a vector. More... | |
CommandLine & | withFinalValue () |
Specify that the command line arguments include one (SEV style) or one or more (SSV style) final stand alone values. More... | |
CommandLine & | withHelpOption (KeyT helpKey, const std::string &shortSwitch, const std::string &longSwitch, const std::string &helpDocumentation) |
Specify the help command line short and long switches. More... | |
CommandLine & | withOption (KeyT key, const std::string &shortSwitch, const std::string &longSwitch, bool hasValue, const std::string &documentation) |
Specify an option that has a short style switch and a long style switch. More... | |
CommandLine & | withOption (KeyT key, const std::string &shortSwitch, bool hasValue, const std::string &documentation) |
Specify an option that has a short style switch. More... | |
CommandLine & | withOptionalFinalValue () |
Specify that the command line arguments include one (SEV style) or one or more (SSV style) final stand alone values. More... | |
A compact command line argument parser.
|
inlineexplicit |
Create a command line parser with the specified style.
style_ | the command line style to use |
|
default |
Create a command line parser by copying the supplied parser.
|
defaultnoexcept |
Create a command line parser by moving the supplied parser.
|
inline |
Get the final value with the specified index as a string or throw if no final value is available.
OptionNotFoundException | if this parser does not have final values or the index is out of range |
|
inline |
Get the final value as a double or throw if no final value is available.
OptionNotFoundException | if no final value exists or the parser does not have final values |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the final value as a double or return the supplied default if no final value is available.
OptionNotFoundException | if no final value exists or the parser does not have final values |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the final value as a float or throw if no final value is available.
OptionNotFoundException | if no final value exists or the parser does not have final values |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the final value as a float or return the supplied default if no final value is available.
OptionNotFoundException | if no final value exists or the parser does not have final values |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the number of final values available.
This will be zero or 1 for SEV style command lines, or zero or more for SSV style command lines.
|
inline |
Get the final value as a string or return the supplied default if no final value is available.
|
inline |
Get the help text.
For parsers that are configured with CommandLineStyle::Detect, the help text will default to switch-space-value unless this is overridden here.
If both styles need to be communicated, this method can be called twice with different overrides.
Note that the implementation of this method does not current do word break analysis, thus it is currently up to the end developer to ensure words are not cut across lines (patches to implement word break analysis are welcome).
|
inline |
Get the specified option value as a UTF-8 string.
OptionNotFoundException | if no such option was provided in the command line |
|
inline |
Get the specified option value as a double.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a double or return the supplied value if there is no such option.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a float.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a float or return the supplied value if there is no such option.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a signed integer value.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a signed int, or the specified default if there is no such option.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a signed long long value.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a signed long long, or the specified default if there is no such option.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a signed short value.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a signed short, or the specified default if there is no such option.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as an unsigned integer value.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as an unsigned int, or the specified default if there is no such option.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as an unsigned long long value.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as an unsigned long long, or the specified default if there is no such option.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as an unsigned short value.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as an unsigned short, or the specified default if there is no such option.
OptionNotFoundException | if the specified option was not found in the parsed command line |
OptionValueException | if the value supplied on the command line was invalid |
|
inline |
Get the specified option value as a string, or the specified default if there is no such option.
|
inline |
Does the command line option set have the specified option?
|
default |
Assign the current command line parser to a copy of the supplied parser.
|
defaultnoexcept |
Assign the current command line parser by moving the contents of the supplied parser.
|
inline |
Parse the input arguments.
Pass true for ignoreFirst if the first argument is the program name (normally the case).
If the parser is configured to detect the switch style, the first parsed program argument will be examined. If it starts with a leading '-', the switch style used will be switch-space-value, otherwise the switch style used will be switch-equals-value
|
inline |
Parse the input arguments.
Pass true for ignoreFirst if the first argument is the program name (normally the case).
If the parser is configured to detect the switch style, the first parsed program argument will be examined. If it starts with a leading '-', the switch style used will be switch-space-value, otherwise the switch style used will be switch-equals-value
|
inline |
Parse the input arguments, which are supplied as a vector.
Pass true for ignoreFirst if the first argument is the program name.
If the parser is configured to detect the switch style, the first parsed program argument will be examined. If it starts with a leading '-', the switch style used will be switch-space-value, otherwise the switch style used will be switch-equals-value
MissingFinalValueException | if a final value is required and none was supplied |
OptionNotFoundException | if an option was not found |
MissingOptionValueException | if an option with a required value was specified and no value was provided |
|
inline |
Specify that the command line arguments include one (SEV style) or one or more (SSV style) final stand alone values.
|
inline |
Specify the help command line short and long switches.
Do not specify a leading "-" or "--" for the short and long switches, as the parser will detect these itself according to the switch style specified in the constructor.
|
inline |
Specify an option that has a short style switch and a long style switch.
Also specify whether the option has a value.
Do not specify a leading "-" or "--" for the short and long switches, as the parser will detect these itself according to the switch style specified in the constructor.
|
inline |
Specify an option that has a short style switch.
Also specify whether the option has a value.
Do not specify a leading "-" for the short switch, as the parser will detect these itself according to the switch style specified in the constructor.
|
inline |
Specify that the command line arguments include one (SEV style) or one or more (SSV style) final stand alone values.