Ookii.CommandLine for C++  2.0.0
Public Member Functions | List of all members
ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType > Class Template Reference

Specifies options common to all argument types, for an argument under construction. More...

#include <ookii/command_line_builder.h>

Inheritance diagram for ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >:
Inheritance graph
[legend]
Collaboration diagram for ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >:
Collaboration graph
[legend]

Public Member Functions

BuilderType & alias (string_type alias)
 Adds an alias to the argument. More...
 
 argument_builder_base (argument_builder_base &)=delete
 Deleted copy constructor.
 
 argument_builder_base (basic_parser_builder &basic_parser_builder, CharType short_name)
 Initializes a new instance of the argument_builder_base class. More...
 
 argument_builder_base (basic_parser_builder &basic_parser_builder, string_type name)
 Initializes a new instance of the argument_builder_base class. More...
 
BuilderType & cancel_parsing ()
 Indicates that supplying this argument will cancel parsing. More...
 
BuilderType & description (string_type description)
 Sets the long description for the argument. More...
 
const string_typename () const noexcept
 Returns the name of the argument. More...
 
BuilderType & name (string_type name)
 Changes the name of the argument. More...
 
BuilderType & positional ()
 Indicates that the argument can be specified by position. More...
 
BuilderType & required ()
 Indicates that the argument is required. More...
 
BuilderType & short_alias (CharType alias)
 Adds a short alias to the argument. More...
 
BuilderType & short_name ()
 Sets a short name for the argument that matches the first character of the long name. More...
 
const CharType & short_name () const noexcept
 Returns the short name of the argument. More...
 
BuilderType & short_name (CharType short_name)
 Sets an explicit short name for an argument. More...
 
BuilderType & value_description (string_type value_description)
 Sets the value description for the argument. More...
 
- Public Member Functions inherited from ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_base
 argument_builder_base (argument_builder_base &)=delete
 Deleted copy constructor.
 
virtual ~argument_builder_base ()=default
 Default destructor.
 
template<typename Action >
action_argument_builder< details::first_argument_type< Action > > & add_action_argument (Action action, CharType short_name)
 Adds a new action argument. More...
 
template<typename Action >
action_argument_builder< details::first_argument_type< Action > > & add_action_argument (Action action, string_type name)
 Adds a new action argument. More...
 
template<typename T >
argument_builder< T > & add_argument (T &value, CharType short_name)
 Adds a new argument, and returns an argument_builder that can be used to further customize it. More...
 
template<typename T >
argument_builder< T > & 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 > & add_multi_value_argument (T &value, CharType short_name)
 Adds a new multi-value argument. More...
 
template<typename T >
multi_value_argument_builder< T > & add_multi_value_argument (T &value, string_type name)
 Adds a new multi-value argument. More...
 
action_argument_builder< bool > & add_version_argument (version_function function)
 Adds the standard version argument. More...
 
action_argument_builder< bool > & add_win32_version_argument ()
 Adds the standard version argument, using version information from the VERSIONINFO resource. More...
 
parser_type build ()
 Creates a basic_command_line_parser using the current options and arguments. More...
 
const string_typename () const noexcept
 Returns the name of the argument.
 
argument_builder_baseoperator= (argument_builder_base &)=delete
 
const CharType & short_name () const noexcept
 Returns the short name of the argument.
 
virtual std::unique_ptr< argument_base_typeto_argument (parser_type &parser)=0
 Converts the argument_builder_base into a command_line_argument_base that can be used by the basic_command_line_parser. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_base
 argument_builder_base (basic_parser_builder &basic_parser_builder, CharType short_name)
 Initializes a new instance of the argument_builder_base class. More...
 
 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.
 

Detailed Description

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType>
class ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >

Specifies options common to all argument types, for an argument under construction.

Template Parameters
BuilderTypeThe type of the the argument builder that is deriving from this class.

Member Function Documentation

◆ alias()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::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.

When using parsing_mode::long_short, this sets the long aliases. They are ignored if the argument does not have a long name.

◆ argument_builder_base() [1/2]

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_base::argument_builder_base
inline

Initializes a new instance of the argument_builder_base class.

Parameters
basic_parser_builderA reference to the basic_parser_builder used to build this argument.
short_nameThe short name of the argument.

◆ argument_builder_base() [2/2]

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_base::argument_builder_base
inline

Initializes a new instance of the argument_builder_base class.

Parameters
basic_parser_builderA reference to the basic_parser_builder used to build this argument.
nameThe name of the argument.

◆ cancel_parsing()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::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.

◆ description()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::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).

◆ name() [1/2]

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
const string_type& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::name ( ) const
inlinenoexcept

Returns the name of the argument.

◆ name() [2/2]

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::name ( string_type  name)
inline

Changes the name of the argument.

If using parsing_mode::long_short, this will give the argument a long name if it didn't already have one.

Parameters
nameThe new name.

◆ positional()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::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 BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::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.

◆ short_alias()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::short_alias ( CharType  alias)
inline

Adds a short alias to the argument.

Parameters
aliasThe short alias to add.

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

This is only used when using parsing_mode::long_short, and the argument has a short name.

◆ short_name() [1/3]

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::short_name ( )
inline

Sets a short name for the argument that matches the first character of the long name.

Warning
If you change the long name of this argument after this call, the short name does not get updated.

◆ short_name() [2/3]

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
const CharType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::short_name ( ) const
inlinenoexcept

Returns the short name of the argument.

◆ short_name() [3/3]

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::short_name ( CharType  short_name)
inline

Sets an explicit short name for an argument.

Parameters
short_nameThe short name.

Use short_name() to use the first character of the long name as the short name.

◆ value_description()

template<typename CharType = details::default_char_type, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename BuilderType >
BuilderType& ookii::basic_parser_builder< CharType, Traits, Alloc >::argument_builder_common< BuilderType >::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: