CPP-AP 2.2.6
Command-line argument parser for C++20
Loading...
Searching...
No Matches
ap::detail::argument_descriptor Class Reference

A structure used to represent an argument's description. More...

#include <argument_descriptor.hpp>

Public Member Functions

 argument_descriptor (const std::string &name, const std::optional< std::string > &help)
 
void add_param (const std::string &name, const std::string &value)
 Adds a parameter descriptor with the given string value.
 
template<c_writable T>
void add_param (const std::string &name, const T &value)
 Adds a parameter descriptor with the given value.
 
template<std::ranges::range R>
requires (c_writable<std::ranges::range_value_t<R>>)
void add_range_param (const std::string &name, const R &range, const std::string_view delimiter=default_delimiter)
 Adds a range parameter descriptor with the given value.
 
std::string get_basic (const uint8_t indent_width, const std::optional< std::size_t > align_to=std::nullopt) const
 
std::string get (const uint8_t indent_width, std::optional< std::size_t > max_line_width=std::nullopt) const
 

Public Attributes

std::string name
 
std::optional< std::string > help
 
std::vector< parameter_descriptorparams
 

Detailed Description

A structure used to represent an argument's description.

Definition at line 32 of file argument_descriptor.hpp.

Constructor & Destructor Documentation

◆ argument_descriptor()

ap::detail::argument_descriptor::argument_descriptor ( const std::string &  name,
const std::optional< std::string > &  help 
)
inline
Parameters
nameThe string representation of the argument's name.
helpAn optional help message string.

Definition at line 38 of file argument_descriptor.hpp.

Member Function Documentation

◆ add_param() [1/2]

void ap::detail::argument_descriptor::add_param ( const std::string &  name,
const std::string &  value 
)
inline

Adds a parameter descriptor with the given string value.

Parameters
nameThe parameter's name.
valueThe parameter's value's string representation.

Definition at line 46 of file argument_descriptor.hpp.

◆ add_param() [2/2]

template<c_writable T>
void ap::detail::argument_descriptor::add_param ( const std::string &  name,
const T &  value 
)
inline

Adds a parameter descriptor with the given value.

Template Parameters
TThe type of the parameter; must satisfy the ap::detail::c_writable concept.
Parameters
nameThe parameter's name.
valueThe parameter's value.

Definition at line 57 of file argument_descriptor.hpp.

◆ add_range_param()

template<std::ranges::range R>
requires (c_writable<std::ranges::range_value_t<R>>)
void ap::detail::argument_descriptor::add_range_param ( const std::string &  name,
const R &  range,
const std::string_view  delimiter = default_delimiter 
)
inline

Adds a range parameter descriptor with the given value.

Template Parameters
RThe type of the parameter range. The value type of R must satisfy the ap::detail::c_writable concept.
Parameters
nameThe parameter's name.
rangeThe parameter value range.
delimiterThe delimiter used to separate the range values.

Definition at line 72 of file argument_descriptor.hpp.

◆ get()

std::string ap::detail::argument_descriptor::get ( const uint8_t  indent_width,
std::optional< std::size_t >  max_line_width = std::nullopt 
) const
inline

Generates a full string representation of the argument descriptor, optionally formatted to fit within a specified maximum line width. The output includes the argument name, help message (if present), and any added parameters.

If no parameters are present, or the generated one-line representation fits within the max_line_width, a single-line format is used: "<indent><arg-name> : <help-msg> (<param1>: <value1>, ...)"

Otherwise, a multi-line format is returned, listing each parameter on its own line with additional indentation.

Parameters
indent_widthThe number of spaces to insert before the argument name.
max_line_widthOptional maximum number of characters allowed for the one-line representation. If the one-line output exceeds this, a multi-line format is used instead.
Returns
A formatted string describing the argument and its parameters.
Note
The help message is only included if it is not std::nullopt.

Definition at line 120 of file argument_descriptor.hpp.

◆ get_basic()

std::string ap::detail::argument_descriptor::get_basic ( const uint8_t  indent_width,
const std::optional< std::size_t >  align_to = std::nullopt 
) const
inline
Parameters
indent_widthThe indentation width.
align_toOptional minimum width for the argument name; if provided, the name will be left-aligned and padded with spaces to this width.
Returns
A basic argument description in the format "<indent><arg-name> : <help-msg>"
Note
The help message will only be visible in the output if it's not std::nullopt

Definition at line 86 of file argument_descriptor.hpp.

Member Data Documentation

◆ help

std::optional<std::string> ap::detail::argument_descriptor::help

Definition at line 138 of file argument_descriptor.hpp.

◆ name

std::string ap::detail::argument_descriptor::name

Definition at line 137 of file argument_descriptor.hpp.

◆ params

std::vector<parameter_descriptor> ap::detail::argument_descriptor::params

Definition at line 139 of file argument_descriptor.hpp.


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