29namespace seqan3::detail
43 template <
typename value_type>
44 static std::string get_type_name_as_string(value_type
const & )
47 using types = type_list<int8_t,
62 "unsigned 8 bit integer",
63 "signed 16 bit integer",
64 "unsigned 16 bit integer",
65 "signed 32 bit integer",
66 "unsigned 32 bit integer",
67 "signed 64 bit integer",
68 "unsigned 64 bit integer",
74 "std::filesystem::path"};
76 if constexpr (list_traits::contains<type, types>)
77 return names[list_traits::find<type, types>];
79 return detail::type_name_as_string<value_type>;
86 template <detail::is_container_option container_type>
87 static std::string get_type_name_as_string(container_type
const & )
89 typename container_type::value_type tmp{};
90 return get_type_name_as_string(tmp);
98 template <
typename option_value_type>
99 static std::string option_type_and_list_info(option_value_type
const & value)
101 return (
"(\\fI" + get_type_name_as_string(value) +
"\\fP)");
110 template <detail::is_container_option container_type>
113 return (
"(\\fIList\\fP of \\fI" + get_type_name_as_string(
container) +
"\\fP)");
127 if (short_id !=
'\0')
128 term =
"\\fB-" +
std::string(1, short_id) +
"\\fP";
130 if (short_id !=
'\0' && !long_id.
empty())
133 if (!long_id.
empty())
134 term.
append(
"\\fB--" + long_id +
"\\fP");
150 for (
auto c : original)
178 auto it{flag_cluster.
begin()};
180 if (flag_cluster[0] ==
'-')
183 for (; it != flag_cluster.
end() - 1; ++it)
184 tmp.
append({
'-', *it,
',',
' '});
187 tmp.
append({
'a',
'n',
'd',
' ',
'-', flag_cluster[flag_cluster.
size() - 1]});
198template <
typename derived_type>
199class format_help_base :
public format_base
205 format_help_base() =
default;
206 format_help_base(format_help_base
const & pf) =
default;
207 format_help_base & operator=(format_help_base
const & pf) =
default;
208 format_help_base(format_help_base &&) =
default;
209 format_help_base & operator=(format_help_base &&) =
default;
210 ~format_help_base() =
default;
217 command_names{names},
226 template <
typename option_type,
typename val
idator_type>
227 void add_option(option_type & value,
232 validator_type && option_validator)
234 std::string id = prep_id_for_help(short_id, long_id) +
" " + option_type_and_list_info(value);
237 info += option_validator.get_help_page_message();
238 store_help_page_element(
241 derived_t().print_list_item(
id, info);
249 void add_flag(
bool & SEQAN3_DOXYGEN_ONLY(value),
255 std::string id = prep_id_for_help(short_id, long_id);
256 store_help_page_element(
259 derived_t().print_list_item(
id, desc);
267 template <
typename option_type,
typename val
idator_type>
268 void add_positional_option(option_type & value,
std::string const & desc, validator_type & option_validator)
270 std::string msg = option_validator.get_help_page_message();
273 [
this, &value, desc, msg]()
275 ++positional_option_count;
276 derived_t().print_list_item(detail::to_string(
"\\fBARGUMENT-",
277 positional_option_count,
279 option_type_and_list_info(value)),
282 ((detail::is_container_option<option_type>)
283 ? detail::to_string(
" Default: ", value,
". ")
292 void parse(argument_parser_meta_data & parser_meta)
296 derived_t().print_header();
298 if (!meta.synopsis.empty())
300 derived_t().print_section(
"Synopsis");
301 derived_t().print_synopsis();
304 if (!meta.description.empty())
306 derived_t().print_section(
"Description");
307 for (
auto desc : meta.description)
311 if (!command_names.empty())
313 derived_t().print_section(
"Subcommands");
314 derived_t().print_line(
"This program must be invoked with one of the following subcommands:",
false);
316 derived_t().print_line(
"- \\fB" + name +
"\\fP",
false);
317 derived_t().print_line(
"See the respective help page for further details (e.g. by calling " + meta.app_name
318 +
" " + command_names[0] +
" -h).",
320 derived_t().print_line(
"The following options below belong to the top-level parser and need to be "
321 "specified \\fBbefore\\fP the subcommand key word. Every argument after the "
322 "subcommand key word is passed on to the corresponding sub-parser.",
327 if (!positional_option_calls.empty())
328 derived_t().print_section(
"Positional Arguments");
331 for (
auto f : positional_option_calls)
335 if (!parser_set_up_calls.empty())
336 derived_t().print_section(
"Options");
339 for (
auto f : parser_set_up_calls)
342 if (!meta.examples.empty())
344 derived_t().print_section(
"Examples");
345 for (
auto example : meta.examples)
353 derived_t().print_footer();
363 store_help_page_element(
366 derived_t().print_section(title);
376 store_help_page_element(
379 derived_t().print_subsection(title);
389 store_help_page_element(
390 [
this, text, is_paragraph]()
392 derived_t().print_line(text, is_paragraph);
402 store_help_page_element(
405 derived_t().print_list_item(key, desc);
424 argument_parser_meta_data meta;
431 derived_type & derived_t()
433 return static_cast<derived_type &
>(*this);
437 void print_synopsis()
439 for (
unsigned i = 0; i < meta.synopsis.size(); ++i)
442 text.
append(meta.synopsis[i]);
445 derived_t().print_line(text,
false);
454 derived_t().print_line(text,
true);
463 derived_t().print_section(
"Version");
464 derived_t().print_line(derived_t().in_bold(
"Last update: ") + meta.date,
false);
465 derived_t().print_line(derived_t().in_bold(meta.app_name +
" version: ") + meta.version,
false);
466 derived_t().print_line(derived_t().in_bold(
"SeqAn version: ") + version_str,
false);
468 if (!
empty(meta.url))
470 derived_t().print_section(
"Url");
471 derived_t().print_line(meta.url,
false);
479 if ((!
empty(meta.short_copyright)) || (!
empty(meta.long_copyright)) || (!
empty(meta.citation))
480 || (!
empty(meta.author)) || (!
empty(meta.email)))
482 derived_t().print_section(
"Legal");
484 if (!
empty(meta.short_copyright))
486 derived_t().print_line(derived_t().in_bold(meta.app_name +
" Copyright: ") + meta.short_copyright,
490 if (!
empty(meta.author))
492 derived_t().print_line(derived_t().in_bold(
"Author: ") + meta.author,
false);
495 if (!
empty(meta.email))
497 derived_t().print_line(derived_t().in_bold(
"Contact: ") + meta.email,
false);
500 derived_t().print_line(derived_t().in_bold(
"SeqAn Copyright: ")
501 +
"2006-2022 Knut Reinert, FU-Berlin; released under the 3-clause BSDL.",
504 if (!
empty(meta.citation))
506 derived_t().print_line(derived_t().in_bold(
"In your academic works please cite: ") + meta.citation,
510 if (!
empty(meta.long_copyright))
512 derived_t().print_line(
"For full copyright and/or warranty information see "
513 + derived_t().in_bold(
"--copyright") +
".",
524 unsigned positional_option_count{0};
528 bool show_advanced_options{
true};
544 parser_set_up_calls.
push_back(std::move(printer));
Provides the concept seqan3::detail::is_container_option.
Provides auxiliary information.
Provides parser related exceptions.
T find_first_of(T... args)
T find_last_of(T... args)
option_spec
Used to further specify argument_parser options/flags.
Definition: auxiliary.hpp:248
@ advanced
Definition: auxiliary.hpp:255
@ hidden
Definition: auxiliary.hpp:259
@ required
Definition: auxiliary.hpp:250
The (most general) container concept as defined by the standard library.
constexpr char const * seqan3_version_cstring
The full version as null terminated string.
Definition: version.hpp:67
Provides traits to inspect some information of a type, for example its name.
Provides some standard validators for (positional) options.
Provides SeqAn version macros and global variables.