|
Fancy argparser
Single file argument parser for c++
|
This class represents argument configuration which should be passed to ArgumentParser objects instance. More...
#include <argparse.h>
Public Member Functions | |
| Argument & | SetRequired (bool required) |
| Setter function to flag,. | |
| Argument & | SetNumberOfArguments (int amount) |
| setter function for m_nargs with desired amount | |
| Argument & | SetAnyNumberOfArgumentsButAtLeastOne () |
| Handy setter for argument count with self declared name. | |
| Argument & | SetAnyNumberOfArguments () |
| Handy setter for argument count with self declared name. | |
| Argument & | SetArgumentIsFlag () |
| Handy setter for argument which is actually a flag (e.g. | |
| Argument & | SetType (ArgTypeCast argType) |
| Setter function for type of current argument. | |
| Argument & | SetPositionalName (const std::string &name) |
| Handy setter for positional argument. | |
| Argument & | SetShortName (const std::string &name) |
| Handy setter for short named argument. | |
| Argument & | SetLongName (const std::string &name) |
| Handy setter for long named argument. | |
| Argument & | SetHelp (const std::string &help) |
| Handy setter for additional help. | |
| Argument & | SetChoices (const std::vector< std::string > &choices) |
| Handy setter of valid choices for arguments with string type. | |
| Argument & | SetChoices (std::initializer_list< const char * > choices) |
| Overload so a braced list of string literals – e.g. | |
| Argument & | SetChoices (const std::vector< int > &choices) |
| Handy setter of valid choices for arguments with int type. | |
| Argument & | SetChoices (const std::vector< long long > &choices) |
| Handy setter of valid choices for arguments with long long type. | |
| Argument & | SetChoices (const std::vector< double > &choices) |
| Handy setter of valid choices for arguments with double type. | |
| Argument & | SetDefault (bool defaultArg) |
| Handy setter for single default argument of bool type. | |
| Argument & | SetDefault (int defaultArg) |
| Handy setter for single default argument of int type. | |
| Argument & | SetDefault (long long defaultArg) |
| Handy setter for single default argument of long long type. | |
| Argument & | SetDefault (double defaultArg) |
| Handy setter for single default argument of double type. | |
| Argument & | SetDefault (std::string defaultArg) |
| Handy setter for single default argument of string type. | |
| Argument & | SetDefault (const std::vector< bool > &defaultArg) |
| Handy setter for vector of default arguments of bool type. | |
| Argument & | SetDefault (const std::vector< int > &defaultArg) |
| Handy setter for vector of default arguments of int type. | |
| Argument & | SetDefault (const std::vector< long long > &defaultArg) |
| Handy setter for vector of default arguments of long long type. | |
| Argument & | SetDefault (const std::vector< double > &defaultArg) |
| Handy setter for vector of default arguments of double type. | |
| Argument & | SetDefault (const std::vector< std::string > &defaultArg) |
| Handy setter for vector of default arguments of string type. | |
| bool | HasDefault () const |
| Getter to indicate does argument has any default value. | |
Static Public Member Functions | |
| static Argument | CreateNamedArgument (const std::string &shortName="", const std::string &longName="", const int argsCount=1, ArgTypeCast argType=ArgTypeCast::e_String, const bool required=true, const std::string &help="") |
| Default constructor positional arguments. | |
| static Argument | CreatePositionalArgument (const std::string &positionalName="", const int argsCount=1, ArgTypeCast argType=ArgTypeCast::e_String, const bool required=true, const std::string &help="") |
| Default function for named arguments. | |
Public Attributes | |
| bool | m_required = true |
| required flag argument If required argument is not set in command line then parsing will fail. | |
| int | m_nargs = 1 |
| variable that indicates count of argument in input use "kAnyArgCount" or "kFromOneToInfiniteArgCount" constants for arguments with variable count. | |
| ArgTypeCast | m_type = ArgTypeCast::e_String |
| Variable that hold type of argument. | |
| std::string | m_positionalName = "" |
| name of positional argument positional arguments name used only to access desired argument from code | |
| std::string | m_shortName = "" |
| arguments short name for non positional argument only shot name used in input with 1 prefix | |
| std::string | m_longName = "" |
| arguments long name. | |
| std::string | m_help = "" |
| additional help info for argument Will be part of generated help | |
| std::vector< std::string > | m_choicesString = {} |
| vector of strings to validate arguments input data. | |
| std::vector< int > | m_choicesInt = {} |
| vector of integers to validate arguments input data. | |
| std::vector< long long > | m_choicesLongLong = {} |
| vector of long longs to validate arguments input data. | |
| std::vector< double > | m_choicesDouble = {} |
| vector of double to validate arguments input data. | |
This class represents argument configuration which should be passed to ArgumentParser objects instance.
Definition at line 125 of file argparse.h.
|
inlinestatic |
Default constructor positional arguments.
You can use class Setters or pass your own values to public members directly.
| shortName | represents short name for named argument which should be passed with one prefix. |
| longName | represents long name for named argument which should be passed with double prefix. |
| argsCount | integer number. You can use "kAnyArgCount", "kFromOneToInfiniteArgCount" for non strict count or any int constant. |
| argType | type of argument. Defined via enum. Supported types are: int, long long, double and bool and string for all other cases. |
| required | Is argument required. Will fail parsing, if required argument are not present. |
| help | Your own custom help string start. |
Definition at line 159 of file argparse.h.
|
inlinestatic |
Default function for named arguments.
You can use class Setters or pass your own values to public members directly.
| positionalName | represents name for positional argument. |
| argsCount | integer number. You can use "kAnyArgCount", "kFromOneToInfiniteArgCount" for non strict count or any int constant. |
| argType | type of argument. Defined via enum. Supported types are: int, long long, double and bool and string for all other cases. |
| required | Is argument required. Will fail parsing, if required argument are not present. |
| help | Your own custom help string start. |
Definition at line 175 of file argparse.h.
|
inline |
Getter to indicate does argument has any default value.
Definition at line 540 of file argparse.h.
|
inline |
Handy setter for argument count with self declared name.
Definition at line 232 of file argparse.h.
|
inline |
Handy setter for argument count with self declared name.
Definition at line 224 of file argparse.h.
|
inline |
Handy setter for argument which is actually a flag (e.g.
has no any parameters)
Definition at line 240 of file argparse.h.
|
inline |
Handy setter of valid choices for arguments with double type.
| choices | vector or initializer list of valid double |
Definition at line 387 of file argparse.h.
|
inline |
Handy setter of valid choices for arguments with int type.
| choices | vector or initializer list of valid ints |
Definition at line 353 of file argparse.h.
|
inline |
Handy setter of valid choices for arguments with long long type.
| choices | vector or initializer list of valid long longs |
Definition at line 370 of file argparse.h.
|
inline |
Handy setter of valid choices for arguments with string type.
| choices | vector or initializer list of valid strings |
Definition at line 326 of file argparse.h.
|
inline |
Overload so a braced list of string literals – e.g.
SetChoices({"+", "-"}) – resolves unambiguously to the string choices instead of colliding with the int/double/long long overloads.
| choices | initializer list of string literals |
Definition at line 341 of file argparse.h.
|
inline |
Handy setter for single default argument of bool type.
| defaultArg | default boolean value |
Definition at line 400 of file argparse.h.
|
inline |
Handy setter for vector of default arguments of bool type.
| defaultArg | vector of default boolean values |
Definition at line 470 of file argparse.h.
|
inline |
Handy setter for vector of default arguments of double type.
| defaultArg | vector of default double values |
Definition at line 512 of file argparse.h.
|
inline |
Handy setter for vector of default arguments of int type.
| defaultArg | vector of default int values |
Definition at line 484 of file argparse.h.
|
inline |
Handy setter for vector of default arguments of long long type.
| defaultArg | vector of default long values |
Definition at line 498 of file argparse.h.
|
inline |
Handy setter for vector of default arguments of string type.
| defaultArg | vector of default string values |
Definition at line 526 of file argparse.h.
|
inline |
Handy setter for single default argument of double type.
| defaultArg | default double value |
Definition at line 442 of file argparse.h.
|
inline |
Handy setter for single default argument of int type.
| defaultArg | default int value |
Definition at line 414 of file argparse.h.
|
inline |
Handy setter for single default argument of long long type.
| defaultArg | default long long value |
Definition at line 428 of file argparse.h.
|
inline |
Handy setter for single default argument of string type.
| defaultArg | default string value |
Definition at line 456 of file argparse.h.
|
inline |
Handy setter for additional help.
| help | string with additional help. Empty by default. |
Definition at line 313 of file argparse.h.
|
inline |
Handy setter for long named argument.
Should been used with double prefix in command line. Can be used for auto-generation of short name if it possible and m_allowAbbrev in ArgumentParsed is "true".
| name | name for positional argument. Empty by default |
Definition at line 300 of file argparse.h.
|
inline |
setter function for m_nargs with desired amount
| amount | int value that indicates amount of argument. Could be "kAnyArgCount" or "kFromOneToInfiniteArgCount", 0 or any other positive integer. |
Definition at line 216 of file argparse.h.
|
inline |
Handy setter for positional argument.
| name | name for positional argument. Empty by default |
Definition at line 267 of file argparse.h.
|
inline |
Setter function to flag,.
| required | - bool value to indicate is argument required or not |
Definition at line 198 of file argparse.h.
|
inline |
Handy setter for short named argument.
Should been used with ordinary prefix in command line. Can be auto-generated if possible when m_allowAbbrev in ArgumentParsed set to true.
| name | name for positional argument. Empty by default |
Definition at line 283 of file argparse.h.
|
inline |
Setter function for type of current argument.
| argType | setter for type of current argument data. Any non string types will be casted while parsing. |
Definition at line 254 of file argparse.h.
| std::vector<double> ARGPARSE_NAMESPACE_NAME::Argument::m_choicesDouble = {} |
vector of double to validate arguments input data.
Empty by default. Will fail parsing if double not is in input list
Definition at line 382 of file argparse.h.
| std::vector<int> ARGPARSE_NAMESPACE_NAME::Argument::m_choicesInt = {} |
vector of integers to validate arguments input data.
Empty by default. Will fail parsing if ints not is in input list
Definition at line 348 of file argparse.h.
| std::vector<long long> ARGPARSE_NAMESPACE_NAME::Argument::m_choicesLongLong = {} |
vector of long longs to validate arguments input data.
Empty by default. Will fail parsing if long longs not is in input list
Definition at line 365 of file argparse.h.
| std::vector<std::string> ARGPARSE_NAMESPACE_NAME::Argument::m_choicesString = {} |
vector of strings to validate arguments input data.
Empty by default. Will fail parsing if string not is in input list
Definition at line 321 of file argparse.h.
| std::string ARGPARSE_NAMESPACE_NAME::Argument::m_help = "" |
additional help info for argument Will be part of generated help
Definition at line 308 of file argparse.h.
| std::string ARGPARSE_NAMESPACE_NAME::Argument::m_longName = "" |
arguments long name.
for non positional arguments only argument long name start with double prefix
Definition at line 292 of file argparse.h.
| int ARGPARSE_NAMESPACE_NAME::Argument::m_nargs = 1 |
variable that indicates count of argument in input use "kAnyArgCount" or "kFromOneToInfiniteArgCount" constants for arguments with variable count.
Any other arguments count will be passed as strict arguments count. 0 is for flags (arguments that doesn't carry any data) set to 1 by default.
Definition at line 210 of file argparse.h.
| std::string ARGPARSE_NAMESPACE_NAME::Argument::m_positionalName = "" |
name of positional argument positional arguments name used only to access desired argument from code
Definition at line 262 of file argparse.h.
| bool ARGPARSE_NAMESPACE_NAME::Argument::m_required = true |
required flag argument If required argument is not set in command line then parsing will fail.
IMPORTANT: ALL arguments – named AND positional – are REQUIRED by default. This differs from Python's argparse, where named options are optional by default. To make an argument optional call SetRequired(false) (or pass required=false to the factory function). Optional flags in particular almost always want SetRequired(false).
Definition at line 193 of file argparse.h.
| std::string ARGPARSE_NAMESPACE_NAME::Argument::m_shortName = "" |
arguments short name for non positional argument only shot name used in input with 1 prefix
Definition at line 276 of file argparse.h.
| ArgTypeCast ARGPARSE_NAMESPACE_NAME::Argument::m_type = ArgTypeCast::e_String |