42 #include <experimental/filesystem> 174 argument_parser(std::string
const app_name,
int const argc,
char const *
const *
const argv)
207 template <
typename option_type, val
idator_concept val
idator_type = detail::default_val
idator<option_type>>
211 std::is_same_v<typename validator_type::value_type, option_type>
215 std::string
const & long_id,
216 std::string
const & desc,
218 validator_type validator = validator_type{})
220 if (id_exists(short_id))
221 throw parser_design_error(
"Option Identifier '" + std::string(1, short_id) +
"' was already used before.");
222 if (id_exists(long_id))
224 if (short_id ==
'\0' && long_id.empty())
229 std::visit([=, &value] (
auto & f) { f.add_option(value, short_id, long_id, desc, spec, validator); }, format);
244 std::string
const & long_id,
245 std::string
const & desc,
248 if (id_exists(short_id))
249 throw parser_design_error(
"Option Identifier '" + std::string(1, short_id) +
"' was already used before.");
250 if (id_exists(long_id))
252 if (short_id ==
'\0' && long_id.empty())
257 std::visit([=, &value] (
auto & f) { f.add_flag(value, short_id, long_id, desc, spec); }, format);
280 template <
typename option_type, val
idator_concept val
idator_type = detail::default_val
idator<option_type>>
284 std::is_same_v<typename validator_type::value_type, option_type>
287 std::string
const & desc,
288 validator_type validator = validator_type{})
292 std::visit([=, &value] (
auto & f) { f.add_positional_option(value, desc, validator); }, format);
375 if (parse_was_called)
378 std::visit([
this] (
auto & f) { f.parse(
info); }, format);
379 parse_was_called =
true;
391 std::visit([&] (
auto & f) { f.add_section(title); }, format);
400 std::visit([&] (
auto & f) { f.add_subsection(title); }, format);
409 void add_line(std::string
const & text,
bool line_is_paragraph)
411 std::visit([&] (
auto & f) { f.add_line(text, line_is_paragraph); }, format);
432 std::visit([&] (
auto & f) { f.add_list_item(key, desc); }, format);
496 bool parse_was_called{
false};
526 void init(
int const argc,
char const *
const *
const argv)
530 format = detail::format_short_help();
534 for(
int i = 1; i < argc; ++i)
536 std::string arg{argv[i]};
538 if (arg ==
"-h" || arg ==
"--help")
540 format = detail::format_help(
false);
543 else if (arg ==
"-hh" || arg ==
"--advanced-help")
545 format = detail::format_help(
true);
548 else if (arg ==
"--version")
550 format = detail::format_version();
553 else if (arg ==
"--export-help")
555 std::string export_format{argv[i+1]};
557 if (export_format ==
"html")
558 format = detail::format_html();
559 else if (export_format ==
"man")
560 format = detail::format_man();
566 "Value of --export-help must be one of [html, man, ctd]");
571 format = detail::format_parse(argc, argv);
579 bool id_exists(std::string
const & long_id)
581 return(!(used_option_ids.insert(long_id)).second);
589 bool id_exists(
char const short_id)
591 return(!(used_option_ids.insert(std::string(1, short_id))).second);
598 std::variant<detail::format_parse,
600 detail::format_short_help,
601 detail::format_version,
604 > format{detail::format_help(0)};
607 std::set<std::string> used_option_ids;
Argument parser exception thrown when an argument could not be casted to the according type...
Definition: exceptions.hpp:144
argument_parser(std::string const app_name, int const argc, char const *const *const argv)
Initializes an argument_parser object from the command line arguments.
Definition: argument_parser.hpp:174
void add_subsection(std::string const &title)
Adds an help page subsection to the seqan3::argument_parser.
Definition: argument_parser.hpp:398
void add_section(std::string const &title)
Adds an help page section to the seqan3::argument_parser.
Definition: argument_parser.hpp:389
The SeqAn command line parser.
Definition: argument_parser.hpp:154
void add_line(std::string const &text, bool line_is_paragraph)
Adds an help page text line to the seqan3::argument_parser.
Definition: argument_parser.hpp:409
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
Concept for input streams.
Argument parser exception that is thrown whenever there is an design error directed at the developer ...
Definition: exceptions.hpp:163
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:286
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:430
argument_parser_meta_data info
Aggregates all parser related meta data (see seqan3::argument_parser_meta_data struct).
Definition: argument_parser.hpp:484
option_spec
Used to further specify argument_parser options/flags.
Definition: auxiliary.hpp:60
~argument_parser()=default
The destructor.
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:213
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:242
void parse()
Initiates the actual command line parsing.
Definition: argument_parser.hpp:373
The default were no checking or special displaying is happening.
Definition: auxiliary.hpp:62