181 char const *
const *
const argv,
189 throw design_error{(
"The application name must only contain alpha-numeric characters or '_' and '-' "
190 "(regex: \"^[a-zA-Z0-9_-]+$\").")};
197 throw design_error{
"The subcommand name must only contain alpha-numeric characters or '_' and '-' "
198 "(regex: \"^[a-zA-Z0-9_-]+$\")."};
239 template <
typename option_type, val
idator val
idator_type = detail::default_val
idator<option_type>>
242 && std::invocable<validator_type, option_type>
248 validator_type option_validator = validator_type{})
251 throw design_error{
"You may only specify flags for the top-level parser."};
257 [=, &value](
auto & f)
259 f.add_option(value, short_id, long_id, desc, spec, option_validator);
282 throw design_error(
"A flag's default value must be false.");
288 [=, &value](
auto & f)
290 f.add_flag(value, short_id, long_id, desc, spec);
315 template <
typename option_type, val
idator val
idator_type = detail::default_val
idator<option_type>>
318 && std::invocable<validator_type, option_type>
321 validator_type option_validator = validator_type{})
324 throw design_error{
"You may only specify flags for the top-level parser."};
327 throw design_error{
"You added a positional option with a list value before so you cannot add "
328 "any other positional options."};
330 if constexpr (detail::is_container_option<option_type>)
336 [=, &value](
auto & f)
338 f.add_positional_option(value, desc, option_validator);
412 throw design_error(
"The function parse() must only be called once!");
419 " which sub-program you want to use: one of ",
421 ". Use -h/--help for more information.")};
429 app_version(std::move(app_version_prom));
447 throw design_error(
"No subcommand was provided at the construction of the argument parser!");
479 template <
typename id_type>
480 requires std::same_as<id_type, char> || std::constructible_from<std::string, id_type>
bool
484 throw design_error{
"You can only ask which options have been set after calling the function `parse()`."};
488 char_or_string_t short_or_long_id = {
id};
490 if constexpr (!std::same_as<id_type, char>)
492 if (short_or_long_id.size() == 1)
494 throw design_error{
"Long option identifiers must be longer than one character! If " + short_or_long_id
495 +
"' was meant to be a short identifier, please pass it as a char ('') not a string"
501 throw design_error{
"You can only ask for option identifiers that you added with add_option() before."};
506 return option_it != end_of_options;
523 f.add_section(title, spec);
539 f.add_subsection(title, spec);
558 f.add_line(text, is_paragraph, spec);
587 f.add_list_item(key, desc, spec);
657 friend struct ::seqan3::detail::test_accessor;
728 void init(
int argc,
char const *
const *
const argv)
736 bool special_format_was_set{
false};
738 for (
int i = 1, argv_len = argc; i < argv_len; ++i)
751 if (arg ==
"-h" || arg ==
"--help")
755 special_format_was_set =
true;
757 else if (arg ==
"-hh" || arg ==
"--advanced-help")
761 special_format_was_set =
true;
763 else if (arg ==
"--version")
766 special_format_was_set =
true;
768 else if (arg.substr(0, 13) ==
"--export-help")
774 export_format = arg.
substr(14);
778 if (argv_len <= i + 1)
780 export_format = {argv[i + 1]};
783 if (export_format ==
"html")
785 else if (export_format ==
"man")
792 "Value must be one of [html, man]"};
794 special_format_was_set =
true;
796 else if (arg ==
"--copyright")
799 special_format_was_set =
true;
801 else if (arg ==
"--version-check")
808 if (arg ==
"1" || arg ==
"true")
810 else if (arg ==
"0" || arg ==
"false")
813 throw validation_error{
"Value for option --version-check must be true (1) or false (0)."};
824 if (!special_format_was_set)
832 add_list_item(
"\\fB-h\\fP, \\fB--help\\fP",
"Prints the help page.");
833 add_list_item(
"\\fB-hh\\fP, \\fB--advanced-help\\fP",
"Prints the help page including advanced options.");
834 add_list_item(
"\\fB--version\\fP",
"Prints the version information.");
835 add_list_item(
"\\fB--copyright\\fP",
"Prints the copyright/license information.");
837 "Export the help page information. Value must be one of [html, man].");
840 "Whether to check for the newest app version. Default: true.");
848 template <
typename id_type>
867 constexpr auto allowed =
is_alnum || is_char<'_'> || is_char<'@'>;
872 throw design_error(
"Option Identifier '" + long_id +
"' was already used before.");
873 if (long_id.
length() == 1)
874 throw design_error(
"Long IDs must be either empty, or longer than one character.");
875 if (!allowed(short_id) && !is_char<'\0'>(short_id))
876 throw design_error(
"Option identifiers may only contain alphanumeric characters, '_', or '@'.");
877 if (long_id.
size() > 0 && is_char<'-'>(long_id[0]))
878 throw design_error(
"First character of long ID cannot be '-'.");
884 if (!(allowed(c) || is_char<
'-'>(c)))
886 "Long identifiers may only contain alphanumeric characters, '_', '-', or '@'.");
889 throw design_error(
"Option Identifiers cannot both be empty.");
The SeqAn command line parser.
Definition: argument_parser.hpp:152
update_notifications version_check_dev_decision
Set on construction and indicates whether the developer deactivates the version check calls completel...
Definition: argument_parser.hpp:651
void add_positional_option(option_type &value, std::string const &desc, validator_type option_validator=validator_type{})
Adds a positional option to the seqan3::argument_parser.
Definition: argument_parser.hpp:319
void add_flag(bool &value, char const short_id, std::string const &long_id, std::string const &desc, option_spec const spec=option_spec::standard)
Adds a flag to the seqan3::argument_parser.
Definition: argument_parser.hpp:275
bool is_option_set(id_type const &id) const
Checks whether the option identifier (id) was set on the command line by the user.
Definition: argument_parser.hpp:481
std::regex app_name_regex
Validates the application name to ensure an escaped server call.
Definition: argument_parser.hpp:663
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::standard, validator_type option_validator=validator_type{})
Adds an option to the seqan3::argument_parser.
Definition: argument_parser.hpp:243
argument_parser(std::string const app_name, int const argc, char const *const *const argv, update_notifications version_updates=update_notifications::on, std::vector< std::string > subcommands={})
Initializes an seqan3::argument_parser object from the command line arguments.
Definition: argument_parser.hpp:179
argument_parser & operator=(argument_parser &&)=default
Defaulted.
~argument_parser()
The destructor.
Definition: argument_parser.hpp:208
argument_parser_meta_data info
Aggregates all parser related meta data (see seqan3::argument_parser_meta_data struct).
Definition: argument_parser.hpp:641
std::unique_ptr< argument_parser > sub_parser
Stores the sub-parser in case subcommand parsing is enabled.
Definition: argument_parser.hpp:669
void verify_identifiers(char const short_id, std::string const &long_id)
Verifies that the short and the long identifiers are correctly formatted.
Definition: argument_parser.hpp:865
std::set< std::string > used_option_ids
List of option/flag identifiers that are already used.
Definition: argument_parser.hpp:691
argument_parser(argument_parser &&)=default
Defaulted.
bool has_positional_list_option
Keeps track of whether the user has added a positional list option to check if this was the very last...
Definition: argument_parser.hpp:648
bool id_exists(id_type const &id)
Checks whether the long identifier has already been used before.
Definition: argument_parser.hpp:849
void parse()
Initiates the actual command line parsing.
Definition: argument_parser.hpp:409
static constexpr std::string_view const end_of_options_indentifier
Signals the argument parser that no options follow this string but only positional arguments.
Definition: argument_parser.hpp:666
argument_parser()=delete
Deleted.
std::future< bool > version_check_future
The future object that keeps track of the detached version check call thread.
Definition: argument_parser.hpp:660
std::vector< std::string > subcommands
Stores the sub-parser names in case subcommand parsing is enabled.
Definition: argument_parser.hpp:672
bool parse_was_called
Keeps track of whether the parse function has been called already.
Definition: argument_parser.hpp:645
void init_standard_options()
Adds standard options to the help page.
Definition: argument_parser.hpp:829
void init(int argc, char const *const *const argv)
Initializes the seqan3::argument_parser class on construction.
Definition: argument_parser.hpp:728
void add_line(std::string const &text, bool is_paragraph=false, option_spec const spec=option_spec::standard)
Adds an help page text line to the seqan3::argument_parser.
Definition: argument_parser.hpp:553
std::vector< std::string > cmd_arguments
The command line arguments.
Definition: argument_parser.hpp:694
void add_list_item(std::string const &key, std::string const &desc, option_spec const spec=option_spec::standard)
Adds an help page list item (key-value) to the seqan3::argument_parser.
Definition: argument_parser.hpp:582
void add_section(std::string const &title, option_spec const spec=option_spec::standard)
Adds an help page section to the seqan3::argument_parser.
Definition: argument_parser.hpp:518
std::optional< bool > version_check_user_decision
Whether the user specified to perform the version check (true) or not (false), default unset.
Definition: argument_parser.hpp:654
std::variant< detail::format_parse, detail::format_help, detail::format_short_help, detail::format_version, detail::format_html, detail::format_man, detail::format_copyright > format
The format of the argument parser that decides the behavior when calling the seqan3::argument_parser:...
Definition: argument_parser.hpp:688
void add_subsection(std::string const &title, option_spec const spec=option_spec::standard)
Adds an help page subsection to the seqan3::argument_parser.
Definition: argument_parser.hpp:534
argument_parser & operator=(argument_parser const &)=default
Defaulted.
argument_parser & get_sub_parser()
Returns a reference to the sub-parser instance if subcommand parsing was enabled.
Definition: argument_parser.hpp:443
argument_parser(argument_parser const &)=default
Defaulted.
Argument parser exception that is thrown whenever there is an design error directed at the developer ...
Definition: exceptions.hpp:151
A functor whose operator() performs the server http request and version checks.
Definition: version_check.hpp:60
Argument parser exception thrown when too few arguments are provided.
Definition: exceptions.hpp:79
Argument parser exception thrown when an argument could not be casted to the according type.
Definition: exceptions.hpp:131
option_spec
Used to further specify argument_parser options/flags.
Definition: auxiliary.hpp:248
@ standard
The default were no checking or special displaying is happening.
Definition: auxiliary.hpp:249
constexpr auto is_alnum
Checks whether c is a alphanumeric character.
Definition: predicate.hpp:197
constexpr ptrdiff_t find
Get the index of the first occurrence of a type in a pack.
Definition: traits.hpp:182
Checks whether the the type can be used in an add_(positional_)option call on the argument parser.
std::string to_string(value_type &&... values)
Streams all parameters via the seqan3::debug_stream and returns a concatenated string.
Definition: to_string.hpp:29
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
update_notifications
Indicates whether application allows automatic update notifications by the seqan3::argument_parser.
Definition: auxiliary.hpp:267
@ off
Automatic update notifications should be disabled.
@ on
Automatic update notifications should be enabled.
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
Forward declares seqan3::detail::test_accessor.
Auxiliary for pretty printing of exception messages.
Provides the version check functionality.