Ookii.CommandLine for C++
1.0.0
|
Abstract base class with common functionality for the argument builders. More...
#include <ookii/command_line_builder.h>
Public Member Functions | |
argument_builder_base (argument_builder_base &)=delete | |
virtual | ~argument_builder_base ()=default |
Default destructor. | |
template<typename T > | |
argument_builder< typed_argument_type< T >, argument_builder_base > & | add_argument (T &value, string_type name) |
Adds a new argument, and returns an argument_builder that can be used to further customize it. More... | |
template<typename T > | |
multi_value_argument_builder< T >::builder_type & | add_multi_value_argument (T &value, string_type name) |
Adds a new multi-value argument, and returns an argument_builder that can be used to further customize it. More... | |
parser_type | build () |
Creates a basic_command_line_parser using the current options and arguments. More... | |
const string_type & | name () const |
Returns the name of the argument. | |
argument_builder_base & | operator= (argument_builder_base &)=delete |
virtual owned_or_borrowed_ptr< argument_base_type > | to_argument ()=0 |
Converts the argument_builder_base into a command_line_argument_base that can be used by the basic_command_line_parser. | |
Protected Member Functions | |
argument_builder_base (basic_parser_builder &basic_parser_builder, string_type name) | |
Initializes a new instance of the argument_builder_base class. More... | |
size_t | get_next_position () |
Gets the next position for a positional argument. | |
storage_type & | storage () |
Provides access to the argument's options storage. | |
Abstract base class with common functionality for the argument builders.
This class contains functionality that doesn't depend on the argument's type.
|
inlineprotected |
Initializes a new instance of the argument_builder_base class.
basic_parser_builder | A reference to the basic_parser_builder used to build this argument. |
name | The name of the argument. |
|
inline |
Adds a new argument, and returns an argument_builder that can be used to further customize it.
T | The type of the argument. |
value | A reference to the storage for the argument's value. When the argument is supplied, the converted value will be written to this reference. |
name | The name of the argument, used to supply it on the command line. |
Any type T can be used as an argument type, as long as it meets the following criteria:
operator>>
), or by a specialization of the lexical_convert template.std::format
(or libfmt if <format> is not available).For custom argument types, you must provide either a stream extractor (operator>>
) or specialize lexical_convert, and you must provide a specialization of std::formatter
(fmt::formatter
if libfmt is being used).
Providing an std::formatter
is required so default values can be displayed in the usage help. A formatter must be provided even if you don't plan to set a default value, to prevent compiler errors (in that case, you could of course provide a non-functional, empty formatter).
Of the argument is of type std::optional<T>
, the requirements apply to the contained type, not the std::optional<T>
itself.
If type T is either bool
or std::optional<bool>
, the resulting argument will be a switch argument.
|
inline |
Adds a new multi-value argument, and returns an argument_builder that can be used to further customize it.
T | The type of the argument's container. |
value | A reference to the container for the argument's values. When the argument is supplied, the converted value will be added to this container. |
name | The name of the argument, used to supply it on the command line. |
Any container type T can be used, provided it meets the following requirements.
|
inline |
Creates a basic_command_line_parser using the current options and arguments.
Since various values are moved out of the basic_parser_builder into the basic_command_line_parser, the basic_parser_builder should not be used after calling build().