Ookii.CommandLine for C++  1.0.0
Public Member Functions | List of all members
ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType > Class Template Reference

Specifies options for an argument under construction. More...

#include <ookii/command_line_builder.h>

Inheritance diagram for ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >:
Inheritance graph
[legend]
Collaboration diagram for ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >:
Collaboration graph
[legend]

Public Member Functions

 argument_builder (basic_parser_builder &basic_parser_builder, string_type name, value_type &value)
 Initializes a new instance of the argument_builder class. More...
 
argument_builderalias (string_type alias)
 Adds an alias to the argument. More...
 
argument_buildercancel_parsing ()
 Indicates that supplying this argument will cancel parsing. More...
 
argument_builderconverter (converter_type converter)
 Supplies a custom function to convert strings to the argument's type. More...
 
argument_builderdefault_value (element_type default_value)
 Sets a default value for the argument, which will be used if the argument is not supplied.. More...
 
argument_builderdescription (string_type description)
 Sets the long description for the argument. More...
 
argument_builderpositional ()
 Indicates that the argument can be specified by position. More...
 
argument_builderrequired ()
 Indicates that the argument is required. More...
 
argument_buildervalue_description (string_type value_description)
 Sets the value description for the argument. More...
 

Detailed Description

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType, typename BaseType>
class ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >

Specifies options for an argument under construction.

This class inherits from argument_builder_base for arguments that are not multi-value, and inherits from multi_value_argument_builder for arguments that are.

Constructor & Destructor Documentation

◆ argument_builder()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::argument_builder ( basic_parser_builder basic_parser_builder,
string_type  name,
value_type &  value 
)
inline

Initializes a new instance of the argument_builder class.

Parameters
basic_parser_builderA reference to the basic_parser_builder used to build this argument.
nameThe name of the argument.
valueA reference where the argument's value will be stored.

Member Function Documentation

◆ alias()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
argument_builder& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::alias ( string_type  alias)
inline

Adds an alias to the argument.

Parameters
aliasThe alias to add.

An alias is an alternate, often shorter, name for an argument that can be used to specify it on the command line. For example, an argument -Verbose might have the alias -v.

An argument can have multiple aliases, which can be specified by invoking this method multiple times.

◆ cancel_parsing()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
argument_builder& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::cancel_parsing ( )
inline

Indicates that supplying this argument will cancel parsing.

If set, if this argument is supplied, argument parsing will immediately return with parse_error::parsing_cancelled. Arguments after this one will not be evaluated.

This can be used, for example, to implement a -Help argument where usage help should be shown when supplied even if the rest of the command line is valid.

Note that parsing will be cancelled regardless of the supplied value. So, e.g. for a switch argument, -Help:false will still cancel parsing and display help. If you want to conditionally cancel parsing, you can do so by using a callback with the basic_command_line_parser::on_parsed() method.

◆ converter()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
argument_builder& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::converter ( converter_type  converter)
inline

Supplies a custom function to convert strings to the argument's type.

Parameters
converterThe function used for conversions.

A conversion function must have the signature std::optional<T>(std::basic_string_view<CharType> value, const std::locale &loc). It should return std::nullopt if the conversion failed.

Even if a custom converter is used, conversion using the default method (stream extraction or a specialized lexical_convert template) must still be possible in order to avoid compiler errors. Use this method if a default conversion exists, but you wish to deviate from it for a specific argument.

◆ default_value()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
argument_builder& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::default_value ( element_type  default_value)
inline

Sets a default value for the argument, which will be used if the argument is not supplied..

Parameters
default_valueThe default value to use.

The default value will be applied after parsing to all non-required arguments that weren't specified on the command line.

If no default value is set, basic_command_line_parser will not change the value of the variable holding the argument's value at all, so you can also initialize the variable to the desired value. The advantage of using default_value is that the value can be included in the usage help.

Setting a default value for a required argument is allowed, but the value will never be used.

◆ description()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
argument_builder& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::description ( string_type  description)
inline

Sets the long description for the argument.

Parameters
descriptionThe new description.

The description is used when generating usage help, and is included in the list of descriptions after the usage syntax.

An argument without a description will not be included in the list of descriptions (but will still be included in the syntax).

◆ positional()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
argument_builder& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::positional ( )
inline

Indicates that the argument can be specified by position.

Calling the positional() method will make the argument positional, assigning it the next available position. Therefore, you should define positional arguments in the order you want them to be specified.

A positional argument can still be specified by name, as well as by position.

If the argument is already positional, this method has no effect.

◆ required()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
argument_builder& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::required ( )
inline

Indicates that the argument is required.

A required argument must be provided, otherwise parsing is not successful. Typically, required arguments should also be positional, but this is not mandatory.

If the argument is already required, this method has no effect.

◆ value_description()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename ArgumentType , typename BaseType >
argument_builder& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder< ArgumentType, BaseType >::value_description ( string_type  value_description)
inline

Sets the value description for the argument.

Parameters
value_descriptionThe new value description.
Returns
The argument builder.

The value description is a brief, often one-word description of the type of values that the argument accepts. It's used as part of the usage help's syntax. An example of a value description could be "number", "string", "name", or someting similarly simple.

For longer descriptions of the argument's purpose, use the description() method instead.

If not specified explicitly, the value description defaults to the short type name (excluding namespace names) of the argument's type. The exact value may depend on your compiler.

The default value description for a type can also be overridden by specializing the value_description template.


The documentation for this class was generated from the following file: