28 namespace seqan3::detail
41 template <
typename value_type>
42 static std::string get_type_name_as_string(value_type
const & )
60 "unsigned 8 bit integer",
61 "signed 16 bit integer",
62 "unsigned 16 bit integer",
63 "signed 32 bit integer",
64 "unsigned 32 bit integer",
65 "signed 64 bit integer",
66 "unsigned 64 bit integer",
72 "std::filesystem::path"};
74 if constexpr (list_traits::contains<type, types>)
75 return names[list_traits::find<type, types>];
77 return detail::type_name_as_string<value_type>;
84 template <sequence_container container_type>
86 requires !std::is_same_v<container_type, std::string>
88 static std::string get_type_name_as_string(container_type
const & )
90 typename container_type::value_type tmp;
91 return get_type_name_as_string(tmp);
99 template <
typename option_value_type>
100 static std::string option_type_and_list_info(option_value_type
const & value)
102 return (
"(\\fI" + get_type_name_as_string(value) +
"\\fP)");
111 template <
typename container_type>
117 return (
"(\\fIList\\fP of \\fI" + get_type_name_as_string(
container) +
"\\fP's)");
131 if (short_id !=
'\0')
132 term =
"\\fB-" +
std::string(1, short_id) +
"\\fP";
134 if (short_id !=
'\0' && !long_id.
empty())
137 if (!long_id.
empty())
138 term.
append(
"\\fB--" + long_id +
"\\fP");
154 for (
auto c : original)
182 auto it{flag_cluster.
begin()};
184 if (flag_cluster[0] ==
'-')
187 for (; it != flag_cluster.
end() - 1; ++it)
201 template <
typename derived_type>
202 class format_help_base :
public format_base
208 format_help_base() =
default;
209 format_help_base(format_help_base
const & pf) =
default;
210 format_help_base & operator=(format_help_base
const & pf) =
default;
211 format_help_base(format_help_base &&) =
default;
212 format_help_base & operator=(format_help_base &&) =
default;
213 ~format_help_base() =
default;
220 command_names{names}, show_advanced_options{advanced}
237 template <
typename option_type,
typename val
idator_type>
238 void add_option(option_type & value,
247 parser_set_up_calls.
push_back([
this, &value, short_id, long_id, desc, spec, msg] ()
250 derived_t().print_list_item(prep_id_for_help(short_id, long_id) +
251 " " + option_type_and_list_info(value),
255 : detail::to_string(
" Default: ", value,
". ")) +
267 void add_flag(
bool & ,
273 parser_set_up_calls.push_back([
this, short_id, long_id, desc, spec] ()
276 derived_t().print_list_item(prep_id_for_help(short_id, long_id), desc);
289 template <
typename option_type,
typename val
idator_type>
290 void add_positional_option(option_type & value,
296 positional_option_calls.
push_back([
this, &value, desc, msg] ()
298 ++positional_option_count;
299 derived_t().print_list_item(detail::to_string(
"\\fBARGUMENT-", positional_option_count,
"\\fP ",
300 option_type_and_list_info(value)),
304 ? detail::to_string(
" Default: ", value,
". ")
313 void parse(argument_parser_meta_data & parser_meta)
317 derived_t().print_header();
319 if (!meta.synopsis.empty())
321 derived_t().print_section(
"Synopsis");
322 derived_t().print_synopsis();
325 if (!meta.description.empty())
327 derived_t().print_section(
"Description");
328 for (
auto desc : meta.description)
332 if (!command_names.empty())
334 derived_t().print_section(
"Subcommands");
335 derived_t().print_line(
"This program must be invoked with one of the following subcommands:",
false);
337 derived_t().print_line(
"- \\fB" + name +
"\\fP",
false);
338 derived_t().print_line(
"See the respective help page for further details (e.g. by calling " +
339 meta.app_name +
" " + command_names[0] +
" -h).",
true);
340 derived_t().print_line(
"The following options below belong to the top-level parser and need to be "
341 "specified \\fBbefore\\fP the subcommand key word. Every argument after the "
342 "subcommand key word is passed on to the corresponding sub-parser.",
true);
346 if (!positional_option_calls.empty())
347 derived_t().print_section(
"Positional Arguments");
350 for (
auto f : positional_option_calls)
354 if (!parser_set_up_calls.empty())
355 derived_t().print_section(
"Options");
358 for (
auto f : parser_set_up_calls)
361 if (!meta.examples.empty())
363 derived_t().print_section(
"Examples");
364 for (
auto example : meta.examples)
368 derived_t().print_footer();
378 parser_set_up_calls.push_back([
this, title] ()
380 derived_t().print_section(title);
389 parser_set_up_calls.push_back([
this, title] ()
391 derived_t().print_subsection(title);
399 void add_line(
std::string const & text,
bool line_is_paragraph)
401 parser_set_up_calls.push_back([
this, text, line_is_paragraph] ()
403 derived_t().print_line(text, line_is_paragraph);
413 parser_set_up_calls.push_back([
this, key, desc] ()
415 derived_t().print_list_item(key, desc);
433 argument_parser_meta_data meta;
440 derived_type & derived_t()
442 return static_cast<derived_type &>(*
this);
446 void print_synopsis()
448 for (
unsigned i = 0; i < meta.synopsis.size(); ++i)
451 text.
append(meta.synopsis[i]);
454 derived_t().print_line(text,
false);
463 derived_t().print_line(text,
true);
471 unsigned positional_option_count{0};
475 bool show_advanced_options{
true};