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}
228 template <
typename option_type,
typename val
idator_type>
229 void add_option(option_type & value,
234 validator_type && option_validator)
236 std::string id = prep_id_for_help(short_id, long_id) +
" " + option_type_and_list_info(value);
239 info += option_validator.get_help_page_message();
240 store_help_page_element([
this,
id, info] () { derived_t().print_list_item(
id, info); }, spec);
246 void add_flag(
bool & SEQAN3_DOXYGEN_ONLY(value),
252 std::string id = prep_id_for_help(short_id, long_id);
253 store_help_page_element([
this,
id, desc] () { derived_t().print_list_item(
id, desc); }, spec);
259 template <
typename option_type,
typename val
idator_type>
260 void add_positional_option(option_type & value,
262 validator_type & option_validator)
264 std::string msg = option_validator.get_help_page_message();
266 positional_option_calls.
push_back([
this, &value, desc, msg] ()
268 ++positional_option_count;
269 derived_t().print_list_item(detail::to_string(
"\\fBARGUMENT-", positional_option_count,
"\\fP ",
270 option_type_and_list_info(value)),
274 ? detail::to_string(
" Default: ", value,
". ")
283 void parse(argument_parser_meta_data & parser_meta)
287 derived_t().print_header();
289 if (!meta.synopsis.empty())
291 derived_t().print_section(
"Synopsis");
292 derived_t().print_synopsis();
295 if (!meta.description.empty())
297 derived_t().print_section(
"Description");
298 for (
auto desc : meta.description)
302 if (!command_names.empty())
304 derived_t().print_section(
"Subcommands");
305 derived_t().print_line(
"This program must be invoked with one of the following subcommands:",
false);
307 derived_t().print_line(
"- \\fB" + name +
"\\fP",
false);
308 derived_t().print_line(
"See the respective help page for further details (e.g. by calling " +
309 meta.app_name +
" " + command_names[0] +
" -h).",
true);
310 derived_t().print_line(
"The following options below belong to the top-level parser and need to be "
311 "specified \\fBbefore\\fP the subcommand key word. Every argument after the "
312 "subcommand key word is passed on to the corresponding sub-parser.",
true);
316 if (!positional_option_calls.empty())
317 derived_t().print_section(
"Positional Arguments");
320 for (
auto f : positional_option_calls)
324 if (!parser_set_up_calls.empty())
325 derived_t().print_section(
"Options");
328 for (
auto f : parser_set_up_calls)
331 if (!meta.examples.empty())
333 derived_t().print_section(
"Examples");
334 for (
auto example : meta.examples)
338 derived_t().print_footer();
348 store_help_page_element([
this, title] () { derived_t().print_section(title); }, spec);
356 store_help_page_element([
this, title] () { derived_t().print_subsection(title); }, spec);
364 store_help_page_element([
this, text, is_paragraph] () { derived_t().print_line(text, is_paragraph); }, spec);
372 store_help_page_element([
this, key, desc] () { derived_t().print_list_item(key, desc); }, spec);
389 argument_parser_meta_data meta;
396 derived_type & derived_t()
398 return static_cast<derived_type &
>(*this);
402 void print_synopsis()
404 for (
unsigned i = 0; i < meta.synopsis.size(); ++i)
407 text.
append(meta.synopsis[i]);
410 derived_t().print_line(text,
false);
419 derived_t().print_line(text,
true);
427 unsigned positional_option_count{0};
431 bool show_advanced_options{
true};