46 void add_param(
const std::string& param_name,
const std::string& value) {
47 this->
params.emplace_back(param_name, value);
56 template <c_writable T>
57 void add_param(
const std::string& param_name,
const T& value) {
58 std::ostringstream oss;
59 oss << std::boolalpha << value;
60 this->
params.emplace_back(param_name, oss.str());
70 template <std::ranges::range R>
73 const std::string& param_name,
77 this->
params.emplace_back(param_name,
join(range, delimiter));
87 const uint8_t indent_width,
const std::optional<std::size_t> align_to = std::nullopt
89 std::ostringstream oss;
91 oss << std::string(indent_width,
' ');
92 if (align_to.has_value())
93 oss << std::setw(static_cast<int>(align_to.value())) << std::left;
96 if (this->
help.has_value())
97 oss <<
" : " << this->
help.value();
120 [[nodiscard]] std::string
get(
121 const uint8_t indent_width, std::optional<std::size_t> max_line_width = std::nullopt
123 std::ostringstream oss;
128 if (max_line_width.has_value()) {
130 if (single_line_str.size() <= max_line_width.value())
131 return single_line_str;
138 std::optional<std::string>
help;
139 std::vector<parameter_descriptor>
params;
149 std::ostringstream oss;
152 if (not this->params.empty()) {
154 <<
join(this->params | std::views::transform(
155 [](
const auto& param) {
return std::format(
"{}: {}", param.name, param.value); }
171 std::ostringstream oss;
175 std::size_t max_param_name_len = 0ull;
176 for (
const auto& param : this->
params)
177 max_param_name_len = std::max(max_param_name_len, param.name.size());
179 for (
const auto& param : this->
params) {
181 << std::string(indent_width * 2,
' ') <<
"- "
182 << std::setw(
static_cast<int>(max_param_name_len)) << std::left << param.name
183 <<
" = " << param.value;
A structure used to represent an argument's description.
static constexpr std::string_view default_delimiter
std::string get(const uint8_t indent_width, std::optional< std::size_t > max_line_width=std::nullopt) const
std::string get_basic(const uint8_t indent_width, const std::optional< std::size_t > align_to=std::nullopt) const
void add_param(const std::string ¶m_name, const std::string &value)
Adds a parameter descriptor with the given string value.
std::string _get_multi_line(const uint8_t indent_width) const
Generates a multi-line string representation of the argument and its parameters, formatting each para...
argument_descriptor(const std::string &name, const std::optional< std::string > &help)
std::optional< std::string > help
void add_param(const std::string ¶m_name, const T &value)
Adds a parameter descriptor with the given value.
void add_range_param(const std::string ¶m_name, const R &range, const std::string_view delimiter=default_delimiter)
Adds a range parameter descriptor with the given value.
std::vector< parameter_descriptor > params
std::string _get_single_line(const uint8_t indent_width) const
Generates a single-line string representation of the argument and its parameters.
The concept is satisfied when T overloads the std::ostream operator <<.
Provides the general concept definitions.
std::string join(const R &range, const std::string_view delimiter=", ")
Joins elements of a range into a single string with a delimiter.
Provides common string utility functions.
A structure used to represent an argument's parameter description.