C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
essence::cli::arg_parser Class Referenceabstract

A parser to handle the command line arguments. More...

#include <arg_parser.hpp>

Public Types

using parse_result_type = abi::map<abi::string, option_result, std::less<>>
 

Public Member Functions

 ES_API (CPPESSENCE) arg_parser()
 Creates an instance.
 
 ES_API (CPPESSENCE) arg_parser(arg_parser &&) noexcept
 
 ES_API (CPPESSENCE) ~arg_parser()
 
 ES_API (CPPESSENCE) arg_parser &operator
 
 ES_API (CPPESSENCE) explicit operator bool() const noexcept
 Checks whether the previous parsing operation succeeds.
 
ES_API(CPPESSENCE) std ES_API (CPPESSENCE) const parse_result_type &cached_result() const noexcept
 Gets the added options.
 
ES_API(CPPESSENCE) std ES_API(CPPESSENCE) void add_option(override ES_API (CPPESSENCE) void parse() const
 Gets the unmatched arguments after parsing.
 
ES_API(CPPESSENCE) void parse(std ES_API(CPPESSENCE) void parse(std ES_API (CPPESSENCE) void show_help() const
 Parses the input command line arguments.
 
 ES_API (CPPESSENCE) void on_error(const output_handler &handler) const
 Subscribes an event to be invoked when an error occurs.
 
 ES_API (CPPESSENCE) void on_output(const output_handler &handler) const
 Subscribes an event to be invoked when a normal output is ready.
 
template<std::default_initializable T>
requires std::is_class_v<T>
std::optional< T > to_model () const
 Fill a data model with the parsed result.
 

Detailed Description

A parser to handle the command line arguments.

Member Function Documentation

◆ ES_API() [1/6]

ES_API(CPPESSENCE) std essence::cli::arg_parser::ES_API ( CPPESSENCE ) const &
nodiscardnoexcept

Gets the added options.

Returns
The added options.

Gets the cached result after parsing.

Returns
The cached result as a map, or an empty map if not exists.

◆ ES_API() [2/6]

essence::cli::arg_parser::ES_API ( CPPESSENCE ) const
noexcept

Checks whether the previous parsing operation succeeds.

Returns
True if succeeds; otherwise false.

◆ ES_API() [3/6]

essence::cli::arg_parser::ES_API ( CPPESSENCE ) const &

Subscribes an event to be invoked when an error occurs.

Parameters
handlerThe handler.

◆ ES_API() [4/6]

essence::cli::arg_parser::ES_API ( CPPESSENCE ) const &

Subscribes an event to be invoked when a normal output is ready.

Parameters
handlerThe handler.

◆ ES_API() [5/6]

ES_API(CPPESSENCE) std ES_API(CPPESSENCE) void add_option(override essence::cli::arg_parser::ES_API ( CPPESSENCE ) const
nodiscardpure virtual

Gets the unmatched arguments after parsing.

Returns
The unmatched arguments.

Adds a new option.

Parameters
optionThe CLI option.

Parses the startup command line arguments.

◆ ES_API() [6/6]

ES_API(CPPESSENCE) void parse(std ES_API(CPPESSENCE) void parse(std essence::cli::arg_parser::ES_API ( CPPESSENCE ) const

Parses the input command line arguments.

Parameters
argcThe count of the arguments.
argvThe array of the arguments.

Parses the input command line arguments.

Parameters
argsThe arguments.

Prints the help string.

◆ to_model()

template<std::default_initializable T>
requires std::is_class_v<T>
std::optional< T > essence::cli::arg_parser::to_model ( ) const
inline

Fill a data model with the parsed result.

Template Parameters
TThe type of the model.
Returns
The filled model.

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