Lector v1.0.0
C++ library for parsing command line arguments.
Classes | Public Member Functions | List of all members
lector::Arguments< ArgumentTypes > Class Template Referencefinal

A collection of command line arguments that can be parsed from argc and argv. More...

#include <arguments.hpp>

Public Member Functions

 Arguments (ArgumentTypes... arguments)
 Constructor. Constructs a collection of command line arguments from a variadic list of command line arguments.
 
 Arguments (const lector::Arguments< ArgumentTypes... > &)=default
 Copy constructor. Constructs a collection of command line argument by copying another one.
 
 Arguments (lector::Arguments< ArgumentTypes... > &&) noexcept=default
 Move constructor. Constructs a collection of command line argument by moving another one.
 
 Arguments (lector::Configuration &&configuration, ArgumentTypes... arguments)
 Compile-time check that all arguments have unique labels.
 
 ~Arguments () noexcept=default
 Destructor. Destroys this collection of command line arguments.
 
const lector::Configurationconfiguration () const
 
const std::filesystem::path & executable_path () const
 Returns the executable path of this collection of command line arguments. If the command line arguments have not yet been parsed from argc and argv, this path is empty.
 
std::string execution () const
 Prints the execution of this collection of command line argument as a string of text. The execution consists of the executable path followed by each argument's longest key and corresponding parsed value, if any.
 
std::string execution (const std::size_t line_length) const
 Prints the execution of this collection of command line argument as a string of text. The execution consists of the executable path followed by each argument's longest key and corresponding parsed value, if any. Lines are wrapped.
 
template<auto Label>
const auto & get () const
 Returns a specified command line argument from this collection.
 
std::string help () const
 Prints the help information of this collection of command line arguments as a string of text. The help information consists of this collection of command line arguments' title, usage information, description, options information, and notes.
 
std::string help (const std::size_t line_length) const
 Prints the help information of this collection of command line arguments as a string of text. The help information consists of this collection of command line arguments' title, usage information, description, options information, and notes. Lines are wrapped.
 
lector::Arguments< ArgumentTypes... > & operator= (const lector::Arguments< ArgumentTypes... > &)=default
 Copy assignment operator. Assigns this collection of command line argument by copying another one.
 
lector::Arguments< ArgumentTypes... > & operator= (lector::Arguments< ArgumentTypes... > &&) noexcept=default
 Move assignment operator. Assigns this collection of command line argument by moving another one.
 
std::string options () const
 Prints the options information of this collection of command line argument as a string of text. The options information consists of the list of each command line argument's keys, value type, and description.
 
std::string options (const std::size_t line_length) const
 Prints the options information of this collection of command line argument as a string of text. The options information consists of the list of each command line argument's keys, value type, and description. Lines are wrapped.
 
void parse (const int argc, char *argv[])
 Parses argc and argv to populate the parsed values of the command line arguments in this collection.
 
std::string usage () const
 Prints the usage information of this collection of command line arguments as a string of text. The usage information consists of each argument's longest key and value type, enclosed in square braces for optional command line arguments.
 
std::string usage (const std::size_t line_length) const
 Prints the usage information of this collection of command line arguments as a string of text. The usage information consists of each argument's longest key and value type, enclosed in square braces for optional command line arguments. Lines are wrapped.
 

Detailed Description

template<typename... ArgumentTypes>
class lector::Arguments< ArgumentTypes >

A collection of command line arguments that can be parsed from argc and argv.

Template Parameters
...ArgumentTypesVariadic list of the types of the command line arguments in this collection.

Constructor & Destructor Documentation

◆ Arguments() [1/4]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::Arguments ( lector::Configuration &&  configuration,
ArgumentTypes...  arguments 
)
explicit

Compile-time check that all arguments have unique labels.

Constructor. Constructs a collection of command line arguments from a configuration data structure and a variadic list of command line arguments.

Parameters
[in]...argumentsThe variadic list of command line arguments.

◆ Arguments() [2/4]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::Arguments ( ArgumentTypes...  arguments)
explicit

Constructor. Constructs a collection of command line arguments from a variadic list of command line arguments.

Parameters
[in]...argumentsThe variadic list of command line arguments.

◆ ~Arguments()

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::~Arguments ( )
defaultnoexcept

Destructor. Destroys this collection of command line arguments.

◆ Arguments() [3/4]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::Arguments ( const lector::Arguments< ArgumentTypes... > &  )
default

Copy constructor. Constructs a collection of command line argument by copying another one.

◆ Arguments() [4/4]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::Arguments ( lector::Arguments< ArgumentTypes... > &&  )
defaultnoexcept

Move constructor. Constructs a collection of command line argument by moving another one.

Member Function Documentation

◆ executable_path()

template<typename... ArgumentTypes>
const std::filesystem::path & lector::Arguments< ArgumentTypes >::executable_path ( ) const

Returns the executable path of this collection of command line arguments. If the command line arguments have not yet been parsed from argc and argv, this path is empty.

Returns
The executable path of this collection of command line arguments.

◆ execution() [1/2]

template<typename... ArgumentTypes>
std::string lector::Arguments< ArgumentTypes >::execution ( ) const

Prints the execution of this collection of command line argument as a string of text. The execution consists of the executable path followed by each argument's longest key and corresponding parsed value, if any.

Returns
The string of text that contains the execution of this collection of command line argument.

◆ execution() [2/2]

template<typename... ArgumentTypes>
std::string lector::Arguments< ArgumentTypes >::execution ( const std::size_t  line_length) const

Prints the execution of this collection of command line argument as a string of text. The execution consists of the executable path followed by each argument's longest key and corresponding parsed value, if any. Lines are wrapped.

Parameters
[in]line_lengthThe desired line length to use when wrapping. Must be strictly greater than zero. The recommended value is 80. The actual line length may be longer if the string of text contains very long words whose lengths exceed the desired line length.
Returns
The string of text that contains the execution of this collection of command line argument.
Exceptions
std::invalid_argumentif the desired line length is zero.

◆ get()

template<typename... ArgumentTypes>
template<auto Label>
const auto & lector::Arguments< ArgumentTypes >::get ( ) const

Returns a specified command line argument from this collection.

Template Parameters
LabelThe label of the command line argument to return.
Returns
The specified command line argument.

◆ help() [1/2]

template<typename... ArgumentTypes>
std::string lector::Arguments< ArgumentTypes >::help ( ) const

Prints the help information of this collection of command line arguments as a string of text. The help information consists of this collection of command line arguments' title, usage information, description, options information, and notes.

Returns
The string of text that contains the help information of this collection of command line arguments.

◆ help() [2/2]

template<typename... ArgumentTypes>
std::string lector::Arguments< ArgumentTypes >::help ( const std::size_t  line_length) const

Prints the help information of this collection of command line arguments as a string of text. The help information consists of this collection of command line arguments' title, usage information, description, options information, and notes. Lines are wrapped.

Parameters
[in]line_lengthThe desired line length to use when wrapping. Must be strictly greater than zero. The recommended value is 80. The actual line length may be longer if the string of text contains very long words whose lengths exceed the desired line length.
Returns
The string of text that contains the help information of this collection of command line arguments.
Exceptions
std::invalid_argumentif the desired line length is zero.

◆ operator=() [1/2]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes... > & lector::Arguments< ArgumentTypes >::operator= ( const lector::Arguments< ArgumentTypes... > &  )
default

Copy assignment operator. Assigns this collection of command line argument by copying another one.

Returns
This collection of command line argument after the assignment.

◆ operator=() [2/2]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes... > & lector::Arguments< ArgumentTypes >::operator= ( lector::Arguments< ArgumentTypes... > &&  )
defaultnoexcept

Move assignment operator. Assigns this collection of command line argument by moving another one.

Returns
This collection of command line argument after the assignment.

◆ options() [1/2]

template<typename... ArgumentTypes>
std::string lector::Arguments< ArgumentTypes >::options ( ) const

Prints the options information of this collection of command line argument as a string of text. The options information consists of the list of each command line argument's keys, value type, and description.

Returns
The string of text that contains the options information of this collection of command line arguments.

◆ options() [2/2]

template<typename... ArgumentTypes>
std::string lector::Arguments< ArgumentTypes >::options ( const std::size_t  line_length) const

Prints the options information of this collection of command line argument as a string of text. The options information consists of the list of each command line argument's keys, value type, and description. Lines are wrapped.

Parameters
[in]line_lengthThe desired line length to use when wrapping. Must be strictly greater than zero. The recommended value is 80. The actual line length may be longer if the string of text contains very long words whose lengths exceed the desired line length.
Returns
The string of text that contains the options information of this collection of command line arguments.
Exceptions
std::invalid_argumentif the desired line length is zero.

◆ parse()

template<typename... ArgumentTypes>
void lector::Arguments< ArgumentTypes >::parse ( const int  argc,
char *  argv[] 
)

Parses argc and argv to populate the parsed values of the command line arguments in this collection.

Parameters
[in]argcThe number of command line arguments, including the executable path.
[in]argvThe array of C-strings that represents the command line arguments, starting with the executable path.
Exceptions
std::invalid_argumentif an invalid, unknown, duplicated, or missing argument is encountered.

◆ usage() [1/2]

template<typename... ArgumentTypes>
std::string lector::Arguments< ArgumentTypes >::usage ( ) const

Prints the usage information of this collection of command line arguments as a string of text. The usage information consists of each argument's longest key and value type, enclosed in square braces for optional command line arguments.

Returns
The string of text that contains the usage information of this collection of command line arguments.

◆ usage() [2/2]

template<typename... ArgumentTypes>
std::string lector::Arguments< ArgumentTypes >::usage ( const std::size_t  line_length) const

Prints the usage information of this collection of command line arguments as a string of text. The usage information consists of each argument's longest key and value type, enclosed in square braces for optional command line arguments. Lines are wrapped.

Parameters
[in]line_lengthThe desired line length to use when wrapping. Must be strictly greater than zero. The recommended value is 80. The actual line length may be longer if the string of text contains very long words whose lengths exceed the desired line length.
Returns
The string of text that contains the usage information of this collection of command line arguments.
Exceptions
std::invalid_argumentif the desired line length is zero.

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