![]() |
mutable
A Database System for Research and Fast Prototyping
|
A parser for command line arguments. More...
#include <ArgParser.hpp>
Data Structures | |
| struct | Option |
| struct | OptionImpl |
Public Member Functions | |
| ArgParser () | |
| ~ArgParser () | |
| template<typename T , is_invocable< T > Callback> | |
| void | add (const char *group_name, const char *short_name, const char *long_name, const char *description, Callback &&callback) |
Adds a new group option to the ArgParser. | |
| template<typename T , is_invocable< T > Callback> | |
| void | add (const char *short_name, const char *long_name, const char *description, Callback &&callback) |
Adds a new option to the ArgParser. | |
| void | print_args (std::ostream &out) const |
Prints a list of all options to out. | |
| void | print_args () const |
Prints a list of all options to std::cout. | |
| void | parse_args (int argc, const char **argv) |
Parses the arguments from argv. | |
| void | operator() (int argc, const char **argv) |
Parses the arguments from argv. | |
| const std::vector< const char * > & | args () const |
| Returns all positional arguments. | |
Private Types | |
| using | options_t = std::vector< std::unique_ptr< const Option > > |
| |
Private Attributes | |
| StringPool | pool_ |
| |
| options_t | general_options_ |
| |
| std::unordered_map< PooledString, options_t > | grouped_options_ |
| |
| std::vector< const char * > | args_ |
| |
| std::unordered_map< PooledString, std::reference_wrapper< const Option > > | key_map_ |
| |
| std::size_t | short_len_ = 0 |
| |
| std::size_t | long_len_ = 0 |
| |
A parser for command line arguments.
Automates the parsing of command line arguments such as short options -s, long options --long, and positional arguments. Can print a nicely formatted help message with a synopsis and explanations of all available options.
Definition at line 19 of file ArgParser.hpp.
|
private |
options type
Definition at line 57 of file ArgParser.hpp.
|
inline |
Definition at line 72 of file ArgParser.hpp.
|
inline |
Definition at line 73 of file ArgParser.hpp.
|
inline |
Adds a new group option to the ArgParser.
| group_name | name of the group; can be nullptr, in which case the option is added to general options |
| short_name | name of the short option, e.g. "-s" |
| long_name | name of the long option, e.g. "--long" |
| description | a textual description of the option |
| callback | a callback function that is invoked if the option is given |
Definition at line 84 of file ArgParser.hpp.
References m::Pooled< T, Pool, CanBeNone >::assert_not_none(), and M_insist.
Referenced by __attribute__(), M_LCOV_EXCL_STOP::__attribute__(), and LIST_CE().
|
inline |
Adds a new option to the ArgParser.
| short_name | name of the short option, e.g. "-s" |
| long_name | name of the long option, e.g. "--long" |
| description | a textual description of the option |
| callback | a callback function that is invoked if the option is given |
Definition at line 119 of file ArgParser.hpp.
|
inline |
Returns all positional arguments.
Definition at line 143 of file ArgParser.hpp.
Referenced by main().
|
inline |
Parses the arguments from argv.
| argc | number of arguments |
| argv | array of c-strings; last element must be nullptr |
Definition at line 140 of file ArgParser.hpp.
| M_LCOV_EXCL_STOP void ArgParser::parse_args | ( | int | argc, |
| const char ** | argv | ||
| ) |
Parses the arguments from argv.
| argc | number of arguments |
| argv | array of c-strings; last element must be nullptr |
Definition at line 186 of file ArgParser.cpp.
References args_, key_map_, pool_, m::streq(), and m::strneq().
Referenced by main().
|
inline |
Prints a list of all options to std::cout.
Definition at line 126 of file ArgParser.hpp.
References print_args().
Referenced by print_args().
| M_LCOV_EXCL_START void ArgParser::print_args | ( | std::ostream & | out | ) | const |
Prints a list of all options to out.
Definition at line 158 of file ArgParser.cpp.
References general_options_, grouped_options_, long_len_, and short_len_.
Referenced by m::operator<<().
|
private |
|
private |
|
private |
|
private |
maps the option name to the option object
Definition at line 65 of file ArgParser.hpp.
Referenced by parse_args().
|
private |
the deducted maximum length of all long options
Definition at line 69 of file ArgParser.hpp.
Referenced by print_args().
|
private |
pool of internalized strings
Definition at line 55 of file ArgParser.hpp.
Referenced by parse_args().
|
private |
the deducted maximum length of all short options
Definition at line 67 of file ArgParser.hpp.
Referenced by print_args().