|
|
using | argument_base_type = command_line_argument_base< CharType, Traits, Alloc > |
| | The specialized type of command_line_argument_base used.
|
| |
| template<typename T > |
| using | argument_type = command_line_argument< T, CharType, Traits, Alloc > |
| | The specialized type of command_line_argument used. More...
|
| |
| template<typename T > |
| using | converter_type = typename argument_type< T >::typed_storage_type::converter_type |
| | The specialized type of the custom command line converter function used. More...
|
| |
|
using | on_parsed_callback = std::function< on_parsed_action(argument_base_type &, string_view_type value)> |
| | The callback function type for on_parsed().
|
| |
|
using | result_type = parse_result< CharType, Traits, Alloc > |
| | The specialized type of parse_result used.
|
| |
|
using | storage_type = details::parser_storage< CharType, Traits, Alloc > |
| | The specialized type of parser parameter storage used. For internal use.
|
| |
|
using | string_type = typename argument_base_type::string_type |
| | The specialized type of std::basic_string used.
|
| |
|
using | string_view_type = std::basic_string_view< CharType, Traits > |
| | The specialized type of std::basic_string_view used.
|
| |
|
using | usage_options_type = basic_usage_options< CharType, Traits, Alloc > |
| | The specialized type of basic_usage_options used.
|
| |
|
| template<typename Range > |
| | basic_command_line_parser (const Range &arguments, storage_type &&storage, bool case_sensitive) |
| | Creates a new instance of the basic_command_line_parser class. More...
|
| |
| bool | allow_duplicate_arguments () const noexcept |
| | Indicates whether duplicate arguments are allowed. More...
|
| |
| bool | allow_white_space_separator () const noexcept |
| | Indicates whether argument names and values can be separated by white space. More...
|
| |
| CharType | argument_value_separator () const noexcept |
| |
| auto | arguments () const |
| | Gets a view of all the arguments defined by the parser. More...
|
| |
| const string_type & | command_name () const noexcept |
| | Returns the command name used when generating usage help. More...
|
| |
| const string_type & | description () const noexcept |
| | Returns the description used when generating usage help. More...
|
| |
| template<typename Func > |
| bool | for_each_argument_in_usage_order (Func f) const |
| | Invokes the specified function on each argument in the order they are shown in in the usage help. More...
|
| |
| const argument_base_type & | get_argument (const string_type &name) const |
| | Gets an argument by name. More...
|
| |
| const argument_base_type & | get_argument (size_t pos) const |
| | Gets an argument by position. More...
|
| |
| const std::locale & | locale () const noexcept |
| | Gets the locale used to parse argument values and to format strings. More...
|
| |
| void | on_parsed (on_parsed_callback callback) |
| | Sets a callback that will be invoked every time an argument is parsed. More...
|
| |
| template<typename Range > |
| result_type | parse (const Range &range) |
| | Parses the arguments in the specified range. More...
|
| |
| result_type | parse (int argc, const CharType *const argv[]) |
| | Parses the provided arguments. More...
|
| |
| result_type | parse (int argc, const CharType *const argv[], const usage_options_type &options) |
| | Parses the provided arguments, and writes error and usage information to the console if a parsing error occurs. More...
|
| |
| template<typename Iterator > |
| result_type | parse (Iterator begin, Iterator end) |
| | Parses the arguments in the range specified by the iterators. More...
|
| |
| template<typename Iterator > |
| result_type | parse (Iterator begin, Iterator end, const usage_options_type &options) |
| | Parses the arguments in the range specified by the iterators, and writes error and usage information to the console if a parsing error occurs. More...
|
| |
| template<typename Range > |
| result_type | parse (Range range, const usage_options_type &options) |
| | Parses the arguments in the specified range, and writes error and usage information to the console if a parsing error occurs. More...
|
| |
| template<typename T > |
| result_type | parse (std::initializer_list< T > args) |
| | Parses the arguments in the specified initializer list. More...
|
| |
| template<typename T > |
| result_type | parse (std::initializer_list< T > args, const usage_options_type &options) |
| | Parses the arguments in the specified initializer list, and writes error and usage information to the console if a parsing error occurs. More...
|
| |
| size_t | positional_argument_count () const |
| | Gets the number of positional arguments. More...
|
| |
| const std::vector< string_type > & | prefixes () const noexcept |
| | Gets a list of all the argument name prefixes accepted by the parser. More...
|
| |
| void | write_usage (const usage_options_type &options={}) |
| | Writes usage help for this parser's arguments. More...
|
| |
template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
class ookii::basic_command_line_parser< CharType, Traits, Alloc >
Parses command line arguments into strongly-typed values.
The basic_command_line_parser class can parse a set of command line arguments in string form into a set of typed values. Which arguments are accepted and where their values will be stored is defined by the basic_parser_builder that created the basic_command_line_parser instance.
In addition, this class can generate detailed usage help for the defined arguments, which can be shown to the user in case an argument parsing error happens or help is requested.
To parse arguments, call one of the overloads of the parse() method. Those overloads taking a basic_usage_options will handle any errors and print the error as well as usage information to the console. Most commonly, the overload you'll want to use is parse(int argc, const CharType *const argv[], const usage_options_type &options).
Two typedefs for common character types are provided:
- Template Parameters
-
| CharType | The character type used for arguments and other strings. Only char and wchar_t are supported. Defaults to wchar_t if _UNICODE is defined, otherwise to char. |
| Traits | The character traits to use for strings. Defaults to std::char_traits<CharType>. |
| Alloc | The allocator to use for strings. Defaults to std::allocator<CharType>. |
template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
Sets a callback that will be invoked every time an argument is parsed.
- Parameters
-
| callback | The callback to be invoked. |
The callback must have the signature on_parsed_action(argument_base_type &arg, string_view_type value).
The callback will be invoked after the argument's value has been set. If the argument's value was invalid, it will not be invoked. The value may be an empty string if this is a switch argument.
The callback can control whether parsing continues with the returned on_parsed_action value.
Only one callback can be registered. Calling this function again will replace the previous callback.