174 char const *
const *
const argv,
175 bool version_check =
true) :
176 version_check_dev_decision{version_check}
186 if (version_check_future.
valid())
212 template <
typename option_type, Val
idator val
idator_type = detail::default_val
idator<option_type>>
223 validator_type validator = validator_type{})
225 verify_identifiers(short_id, long_id);
228 std::visit([=, &value] (
auto & f) { f.add_option(value, short_id, long_id, desc, spec, validator); }, format);
245 verify_identifiers(short_id, long_id);
248 std::visit([=, &value] (
auto & f) { f.add_flag(value, short_id, long_id, desc, spec); }, format);
271 template <
typename option_type, Val
idator val
idator_type = detail::default_val
idator<option_type>>
279 validator_type validator = validator_type{})
283 std::visit([=, &value] (
auto & f) { f.add_positional_option(value, desc, validator); }, format);
359 if (parse_was_called)
364 if (app_version.decide_if_check_is_performed(version_check_dev_decision, version_check_user_decision))
368 version_check_future = app_version_prom.
get_future();
369 app_version(std::move(app_version_prom));
373 parse_was_called =
true;
385 std::visit([&] (
auto & f) { f.add_section(title); }, format);
394 std::visit([&] (
auto & f) { f.add_subsection(title); }, format);
407 std::visit([&] (
auto & f) { f.add_line(text, line_is_paragraph); }, format);
428 std::visit([&] (
auto & f) { f.add_list_item(key, desc); }, format);
484 bool parse_was_called{
false};
487 bool version_check_dev_decision{};
523 void init(
int argc,
char const *
const *
const argv)
530 format = detail::format_short_help{};
534 for(
int i = 1, argv_len = argc; i < argv_len; ++i)
538 if (arg ==
"-h" || arg ==
"--help")
540 format = detail::format_help{
false};
541 init_standard_options();
544 else if (arg ==
"-hh" || arg ==
"--advanced-help")
546 format = detail::format_help{
true};
547 init_standard_options();
550 else if (arg ==
"--version")
552 format = detail::format_version{};
555 else if (arg.substr(0, 13) ==
"--export-help")
561 export_format = arg.
substr(14);
565 if (argv_len <= i + 1)
567 export_format = {argv[i+1]};
570 if (export_format ==
"html")
571 format = detail::format_html{};
572 else if (export_format ==
"man")
573 format = detail::format_man{};
579 "Value must be one of [html, man]"};
580 init_standard_options();
583 else if (arg ==
"--copyright")
585 format = detail::format_copyright{};
588 else if (arg ==
"--version-check")
596 version_check_user_decision =
true;
598 version_check_user_decision =
false;
606 argv_new.push_back(std::move(arg));
610 format = detail::format_parse(argc, std::move(argv_new));
614 void init_standard_options()
617 add_list_item(
"\\fB-h\\fP, \\fB--help\\fP",
"Prints the help page.");
619 "Prints the help page including advanced options.");
620 add_list_item(
"\\fB--version\\fP",
"Prints the version information.");
621 add_list_item(
"\\fB--copyright\\fP",
"Prints the copyright/license information.");
623 "Export the help page information. Value must be one of [html, man].");
624 if (version_check_dev_decision)
625 add_list_item(
"\\fB--version-check\\fP (bool)",
"Whether to to check for the newest app version. Default: 1.");
634 template <
typename id_type>
635 bool id_exists(id_type
const &
id)
637 if (detail::format_parse::is_empty_id(
id))
651 void verify_identifiers(
char const short_id,
std::string const & long_id)
653 auto constexpr allowed =
is_alnum || is_char<'_'> || is_char<'@'>;
655 if (id_exists(short_id))
657 if (id_exists(long_id))
659 if (long_id.
length() == 1)
661 if (!allowed(short_id) && !is_char<'\0'>(short_id))
662 throw parser_design_error(
"Option identifiers may only contain alphanumeric characters, '_', or '@'.");
663 if (long_id.
size() > 0 &&
is_char<
'-'>(long_id[0]))
668 if (!(allowed(c) || is_char<'-'>(c)))
669 throw parser_design_error(
"Long identifiers may only contain alphanumeric characters, '_', '-', or '@'.");
671 if (detail::format_parse::is_empty_id(short_id) && detail::format_parse::is_empty_id(long_id))
681 detail::format_short_help,
682 detail::format_version,
685 detail::format_copyright
686 > format{detail::format_help(0)};
689 std::set<std::string> used_option_ids{
"h",
"hh",
"help",
"advanced-help",
"export-help",
"version",
"copyright"};
void add_line(std::string const &text, bool line_is_paragraph=false)
Adds an help page text line to the seqan3::argument_parser.
Definition: argument_parser.hpp:405
constexpr auto is_char
Checks whether a given letter is the same as the template non-type argument.
Definition: predicate.hpp:83
Concept for input streams.
Argument parser exception thrown when an argument could not be casted to the according type...
Definition: exceptions.hpp:117
void add_subsection(std::string const &title)
Adds an help page subsection to the seqan3::argument_parser.
Definition: argument_parser.hpp:392
void add_section(std::string const &title)
Adds an help page section to the seqan3::argument_parser.
Definition: argument_parser.hpp:383
Specifies whether the given callable is invocable with the given arguments.
The SeqAn command line parser.
Definition: argument_parser.hpp:150
The main SeqAn3 namespace.
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
Argument parser exception that is thrown whenever there is an design error directed at the developer ...
Definition: exceptions.hpp:136
void add_positional_option(option_type &value, std::string const &desc, validator_type validator=validator_type{})
Adds a positional option to the seqan3::argument_parser.
Definition: argument_parser.hpp:277
argument_parser & operator=(argument_parser const &)=default
Defaulted.
argument_parser()=delete
Deleted.
void add_list_item(std::string const &key, std::string const &desc)
Adds an help page list item (key-value) to the seqan3::argument_parser.
Definition: argument_parser.hpp:426
Argument parser exception that is thrown whenever there is an error while parsing the command line ar...
Definition: exceptions.hpp:37
argument_parser_meta_data info
Aggregates all parser related meta data (see seqan3::argument_parser_meta_data struct).
Definition: argument_parser.hpp:480
~argument_parser()
The destructor.
Definition: argument_parser.hpp:183
argument_parser(std::string const app_name, int const argc, char const *const *const argv, bool version_check=true)
Initializes an argument_parser object from the command line arguments.
Definition: argument_parser.hpp:172
Provides character predicates for tokenisation.
Provides the version check functionality.
option_spec
Used to further specify argument_parser options/flags.
Definition: auxiliary.hpp:34
void add_option(option_type &value, char const short_id, std::string const &long_id, std::string const &desc, option_spec const &spec=option_spec::DEFAULT, validator_type validator=validator_type{})
Adds an option to the seqan3::argument_parser.
Definition: argument_parser.hpp:218
void add_flag(bool &value, char const short_id, std::string const &long_id, std::string const &desc, option_spec const &spec=option_spec::DEFAULT)
Adds a flag to the seqan3::argument_parser.
Definition: argument_parser.hpp:239
void parse()
Initiates the actual command line parsing.
Definition: argument_parser.hpp:357
auto constexpr is_alnum
Checks whether c is a alphanumeric character.
Definition: predicate.hpp:220
The default were no checking or special displaying is happening.
Definition: auxiliary.hpp:36