21 #include <meta/meta.hpp> 42 template <
typename value_type>
43 static std::string get_type_name_as_string(value_type
const & )
46 using types = meta::list<int8_t,
61 "unsigned 8 bit integer",
62 "signed 16 bit integer",
63 "unsigned 16 bit integer",
64 "signed 32 bit integer",
65 "unsigned 32 bit integer",
66 "signed 64 bit integer",
67 "unsigned 64 bit integer",
73 "std::filesystem::path"};
75 if constexpr (meta::in<types, type>::value)
76 return names[meta::find_index<types, type>::value];
78 return detail::get_display_name_v<value_type>.str();
85 template <SequenceContainer container_type>
87 requires !std::is_same_v<container_type, std::string>
89 static std::string get_type_name_as_string(container_type
const & )
91 typename container_type::value_type tmp;
92 return get_type_name_as_string(tmp);
100 template <
typename option_value_type>
101 static std::string option_type_and_list_info(option_value_type
const & value)
103 return (
"(\\fI" + get_type_name_as_string(value) +
"\\fP)");
112 template <
typename container_type>
114 requires SequenceContainer<container_type> && !std::is_same_v<container_type, std::string>
116 static std::string option_type_and_list_info(container_type
const & container)
118 return (
"(\\fIList\\fP of \\fI" + get_type_name_as_string(container) +
"\\fP's)");
128 static std::string prep_id_for_help(
char const short_id, std::string
const & long_id)
132 if (short_id !=
'\0')
133 term =
"\\fB-" + std::string(1, short_id) +
"\\fP";
135 if (short_id !=
'\0' && !long_id.
empty())
138 if (!long_id.
empty())
139 term.
append(
"\\fB--" + long_id +
"\\fP");
150 std::string escape_special_xml_chars(std::string
const & original)
155 for (
auto c : original)
180 static std::string expand_multiple_flags(std::string
const & flag_cluster)
183 auto it{flag_cluster.
begin()};
185 if (flag_cluster[0] ==
'-')
188 for (; it != flag_cluster.
end() - 1; ++it)
189 tmp.
append(
"-" + std::string(1, *it) +
", ");
192 tmp.
append(
" and -" + std::string(1, flag_cluster[flag_cluster.
size() - 1]));
202 template <
typename derived_type>
203 class format_help_base :
public format_base
209 format_help_base() =
default;
210 format_help_base(format_help_base
const & pf) =
default;
211 format_help_base & operator=(format_help_base
const & pf) =
default;
212 format_help_base(format_help_base &&) =
default;
213 format_help_base & operator=(format_help_base &&) =
default;
214 ~format_help_base() =
default;
219 format_help_base(
bool const advanced) :
220 show_advanced_options{advanced}
237 template <
typename option_type,
typename val
idator_type>
238 void add_option(option_type & value,
240 std::string
const & long_id,
241 std::string
const & desc,
243 validator_type && validator)
245 parser_set_up_calls.push_back([
this, &value, short_id, long_id, desc, spec, validator] ()
248 derived_t().print_list_item(prep_id_for_help(short_id, long_id) +
249 " " + option_type_and_list_info(value),
250 desc + detail::to_string(
" Default: ", value,
". ") +
251 validator.get_help_page_message());
262 void add_flag(
bool & ,
264 std::string
const & long_id,
265 std::string
const & desc,
268 parser_set_up_calls.push_back([
this, short_id, long_id, desc, spec] ()
270 if (!(spec & option_spec::HIDDEN) && (!(spec & option_spec::ADVANCED) || show_advanced_options))
271 derived_t().print_list_item(prep_id_for_help(short_id, long_id), desc);
284 template <
typename option_type,
typename val
idator_type>
285 void add_positional_option(option_type & value,
286 std::string
const & desc,
287 validator_type & validator)
289 positional_option_calls.push_back([
this, &value, desc, validator] ()
291 ++positional_option_count;
292 derived_t().print_list_item(detail::to_string(
"\\fBARGUMENT-", positional_option_count,
"\\fP ",
293 option_type_and_list_info(value)),
294 desc + detail::to_string(
" Default: ", value,
". ") +
295 validator.get_help_page_message());
302 void parse(argument_parser_meta_data & parser_meta)
306 derived_t().print_header();
308 if (!meta.synopsis.empty())
310 derived_t().print_section(
"Synopsis");
311 derived_t().print_synopsis();
314 if (!meta.description.empty())
316 derived_t().print_section(
"Description");
317 for (
auto desc : meta.description)
322 if (!positional_option_calls.empty())
323 derived_t().print_section(
"Positional Arguments");
326 for (
auto f : positional_option_calls)
330 if (!parser_set_up_calls.empty())
331 derived_t().print_section(
"Options");
334 for (
auto f : parser_set_up_calls)
337 if (!meta.examples.empty())
339 derived_t().print_section(
"Examples");
340 for (
auto example : meta.examples)
344 derived_t().print_footer();
352 void add_section(std::string
const & title)
354 parser_set_up_calls.push_back([
this, title] ()
356 derived_t().print_section(title);
363 void add_subsection(std::string
const & title)
365 parser_set_up_calls.push_back([
this, title] ()
367 derived_t().print_subsection(title);
375 void add_line(std::string
const & text,
bool line_is_paragraph)
377 parser_set_up_calls.push_back([
this, text, line_is_paragraph] ()
379 derived_t().print_line(text, line_is_paragraph);
387 void add_list_item(std::string
const & key, std::string
const & desc)
389 parser_set_up_calls.push_back([
this, key, desc] ()
391 derived_t().print_list_item(key, desc);
409 argument_parser_meta_data meta;
416 derived_type & derived_t()
418 return static_cast<derived_type &
>(*this);
422 void print_synopsis()
424 for (
unsigned i = 0; i < meta.synopsis.size(); ++i)
426 std::string text =
"\\fB";
427 text.
append(meta.synopsis[i]);
430 derived_t().print_line(text,
false);
437 void print_line(std::string
const & text)
439 derived_t().print_line(text,
true);
447 unsigned positional_option_count{0};
449 bool show_advanced_options{
true};
Provides some standard validators for (positional) options.
Definition: auxiliary.hpp:46
Provides parser related exceptions.
T find_last_of(T... args)
T find_first_of(T... args)
Definition: aligned_sequence_concept.hpp:35
Definition: auxiliary.hpp:42
option_spec
Used to further specify argument_parser options/flags.
Definition: auxiliary.hpp:34
Static reflection for arbitrary types.
Provides auxiliary information.
This header includes C++17 filesystem support and imports it into namespace seqan3::filesystem (indep...