30 namespace 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 <sequence_container container_type>
88 requires (!std::is_same_v<container_type, std::string>)
90 static std::string get_type_name_as_string(container_type
const & )
92 typename container_type::value_type tmp{};
93 return get_type_name_as_string(tmp);
101 template <
typename option_value_type>
102 static std::string option_type_and_list_info(option_value_type
const & value)
104 return (
"(\\fI" + get_type_name_as_string(value) +
"\\fP)");
113 template <
typename container_type>
119 return (
"(\\fIList\\fP of \\fI" + get_type_name_as_string(
container) +
"\\fP)");
133 if (short_id !=
'\0')
134 term =
"\\fB-" +
std::string(1, short_id) +
"\\fP";
136 if (short_id !=
'\0' && !long_id.
empty())
139 if (!long_id.
empty())
140 term.
append(
"\\fB--" + long_id +
"\\fP");
156 for (
auto c : original)
184 auto it{flag_cluster.
begin()};
186 if (flag_cluster[0] ==
'-')
189 for (; it != flag_cluster.
end() - 1; ++it)
203 template <
typename derived_type>
204 class format_help_base :
public format_base
210 format_help_base() =
default;
211 format_help_base(format_help_base
const & pf) =
default;
212 format_help_base & operator=(format_help_base
const & pf) =
default;
213 format_help_base(format_help_base &&) =
default;
214 format_help_base & operator=(format_help_base &&) =
default;
215 ~format_help_base() =
default;
222 command_names{names}, show_advanced_options{
advanced}
230 template <
typename option_type,
typename val
idator_type>
231 void add_option(option_type & value,
236 validator_type && option_validator)
238 std::string id = prep_id_for_help(short_id, long_id) +
" " + option_type_and_list_info(value);
241 info += option_validator.get_help_page_message();
242 store_help_page_element([
this,
id, info] () { derived_t().print_list_item(
id, info); }, spec);
248 void add_flag(
bool & SEQAN3_DOXYGEN_ONLY(value),
254 std::string id = prep_id_for_help(short_id, long_id);
255 store_help_page_element([
this,
id, desc] () { derived_t().print_list_item(
id, desc); }, spec);
261 template <
typename option_type,
typename val
idator_type>
262 void add_positional_option(option_type & value,
264 validator_type & option_validator)
266 std::string msg = option_validator.get_help_page_message();
268 positional_option_calls.
push_back([
this, &value, desc, msg] ()
270 ++positional_option_count;
271 derived_t().print_list_item(detail::to_string(
"\\fBARGUMENT-", positional_option_count,
"\\fP ",
272 option_type_and_list_info(value)),
276 ? detail::to_string(
" Default: ", value,
". ")
285 void parse(argument_parser_meta_data & parser_meta)
289 derived_t().print_header();
291 if (!meta.synopsis.empty())
293 derived_t().print_section(
"Synopsis");
294 derived_t().print_synopsis();
297 if (!meta.description.empty())
299 derived_t().print_section(
"Description");
300 for (
auto desc : meta.description)
304 if (!command_names.empty())
306 derived_t().print_section(
"Subcommands");
307 derived_t().print_line(
"This program must be invoked with one of the following subcommands:",
false);
309 derived_t().print_line(
"- \\fB" + name +
"\\fP",
false);
310 derived_t().print_line(
"See the respective help page for further details (e.g. by calling " +
311 meta.app_name +
" " + command_names[0] +
" -h).",
true);
312 derived_t().print_line(
"The following options below belong to the top-level parser and need to be "
313 "specified \\fBbefore\\fP the subcommand key word. Every argument after the "
314 "subcommand key word is passed on to the corresponding sub-parser.",
true);
318 if (!positional_option_calls.empty())
319 derived_t().print_section(
"Positional Arguments");
322 for (
auto f : positional_option_calls)
326 if (!parser_set_up_calls.empty())
327 derived_t().print_section(
"Options");
330 for (
auto f : parser_set_up_calls)
333 if (!meta.examples.empty())
335 derived_t().print_section(
"Examples");
336 for (
auto example : meta.examples)
344 derived_t().print_footer();
354 store_help_page_element([
this, title] () { derived_t().print_section(title); }, spec);
362 store_help_page_element([
this, title] () { derived_t().print_subsection(title); }, spec);
370 store_help_page_element([
this, text, is_paragraph] () { derived_t().print_line(text, is_paragraph); }, spec);
378 store_help_page_element([
this, key, desc] () { derived_t().print_list_item(key, desc); }, spec);
395 argument_parser_meta_data meta;
402 derived_type & derived_t()
404 return static_cast<derived_type &
>(*this);
408 void print_synopsis()
410 for (
unsigned i = 0; i < meta.synopsis.size(); ++i)
413 text.
append(meta.synopsis[i]);
416 derived_t().print_line(text,
false);
425 derived_t().print_line(text,
true);
434 derived_t().print_section(
"Version");
435 derived_t().print_line(derived_t().in_bold(
"Last update: ") + meta.date,
false);
436 derived_t().print_line(derived_t().in_bold(meta.app_name +
" version: ") + meta.version,
false);
437 derived_t().print_line(derived_t().in_bold(
"SeqAn version: ") + version_str,
false);
439 if (!
empty(meta.url))
441 derived_t().print_section(
"Url");
442 derived_t().print_line(meta.url,
false);
450 if ((!
empty(meta.short_copyright)) ||
451 (!
empty(meta.long_copyright)) ||
452 (!
empty(meta.citation)) ||
453 (!
empty(meta.author)) ||
454 (!
empty(meta.email)))
456 derived_t().print_section(
"Legal");
458 if (!
empty(meta.short_copyright))
460 derived_t().print_line(derived_t().in_bold(meta.app_name +
" Copyright: ") + meta.short_copyright,
464 if (!
empty(meta.author))
466 derived_t().print_line(derived_t().in_bold(
"Author: ") + meta.author,
false);
469 if (!
empty(meta.email))
471 derived_t().print_line(derived_t().in_bold(
"Contact: ") + meta.email,
false);
474 derived_t().print_line(derived_t().in_bold(
"SeqAn Copyright: ") +
475 "2006-2021 Knut Reinert, FU-Berlin; released under the 3-clause BSDL.",
false);
477 if (!
empty(meta.citation))
479 derived_t().print_line(derived_t().in_bold(
"In your academic works please cite: ") + meta.citation,
483 if (!
empty(meta.long_copyright))
485 derived_t().print_line(
"For full copyright and/or warranty information see " +
486 derived_t().in_bold(
"--copyright") +
".",
497 unsigned positional_option_count{0};
501 bool show_advanced_options{
true};
Provides auxiliary information.
Provides parser related exceptions.
This header includes C++17 filesystem support and imports it into namespace std::filesystem (independ...
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:238
@ advanced
Definition: auxiliary.hpp:245
@ hidden
Definition: auxiliary.hpp:249
@ required
Definition: auxiliary.hpp:240
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:74
The (most general) container concept as defined by the standard library.
A more refined container concept than seqan3::container.
constexpr char const * seqan3_version_cstring
The full version as null terminated string.
Definition: version.hpp:73
Provides traits to inspect some information of a type, for example its name.
Adaptations of concepts from the standard library.
Provides traits for seqan3::type_list.
Provides some standard validators for (positional) options.
Provides SeqAn version macros and global variables.