SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
|
Classes | |
class | seqan3::argument_parser |
The SeqAn command line parser. More... | |
interface | argument_parser_compatible_option |
Checks whether the the type can be used in an add_(positional_)option call on the argument parser. More... | |
class | seqan3::argument_parser_error |
Argument parser exception that is thrown whenever there is an error while parsing the command line arguments. More... | |
struct | seqan3::argument_parser_meta_data |
Stores all parser related meta information of the seqan3::argument_parser. More... | |
struct | seqan3::custom::argument_parsing< t > |
A type that can be specialised to provide customisation point implementations for the seqan3::argument_parser such that third party types may be adapted. More... | |
class | seqan3::arithmetic_range_validator< option_value_t > |
A validator that checks whether a number is inside a given range. More... | |
struct | seqan3::enumeration_printer< enum_t > |
A type (e.g. an enum) can be made debug streamable by customizing the seqan3::enumeration_names. More... | |
class | seqan3::file_validator_base |
An abstract base class for the file and directory validators. More... | |
class | seqan3::input_directory_validator |
A validator that checks if a given path is a valid input directory. More... | |
class | seqan3::input_file_validator< file_t > |
A validator that checks if a given path is a valid input file. More... | |
interface | named_enumeration |
Checks whether the free function seqan3::enumeration_names can be called on the type. More... | |
class | seqan3::option_declared_multiple_times |
Argument parser exception thrown when a non-list option is declared multiple times. More... | |
class | seqan3::output_directory_validator |
A validator that checks if a given path is a valid output directory. More... | |
class | seqan3::output_file_validator< file_t > |
A validator that checks if a given path is a valid output file. More... | |
class | seqan3::regex_validator |
A validator that checks if a matches a regular expression pattern. More... | |
class | seqan3::required_option_missing |
Argument parser exception thrown when a required option is missing. More... | |
class | seqan3::too_few_arguments |
Argument parser exception thrown when too few arguments are provided. More... | |
class | seqan3::too_many_arguments |
Argument parser exception thrown when too many arguments are provided. More... | |
class | seqan3::unknown_option |
Argument parser exception thrown when encountering unknown option. More... | |
class | seqan3::user_input_error |
Argument parser exception thrown when an incorrect argument is given as (positional) option value. More... | |
class | seqan3::validation_error |
Argument parser exception thrown when an argument could not be casted to the according type. More... | |
interface | validator |
The concept for option validators passed to add_option/positional_option. More... | |
class | seqan3::value_list_validator< option_value_t > |
A validator that checks whether a value is inside a list of valid values. More... | |
Enumerations | |
enum | seqan3::option_spec { seqan3::standard = 0 , seqan3::required = 1 , seqan3::advanced = 2 , seqan3::hidden = 4 } |
Used to further specify argument_parser options/flags. More... | |
Functions | |
template<validator validator1_type, validator validator2_type> requires std::common_with<typename std::remove_reference_t<validator1_type>::option_value_type, typename std::remove_reference_t<validator2_type>::option_value_type> | |
auto | seqan3::operator| (validator1_type &&vali1, validator2_type &&vali2) |
Enables the chaining of validators. | |
Customisation Points | |
template<typename option_type > | |
auto const | seqan3::enumeration_names = detail::adl_only::enumeration_names_cpo<option_type>{}() |
Return a conversion map from std::string_view to option_type. | |
The seqan3::argument_parser is a general purpose argument parser that provides convenient access to the command line arguments passed to the program. It automatically generates a help page and can export manual-pages as well as HTML documentation.
Furthermore common tool descriptor (CTD) files can be exported (soon) and a server be queried for available application updates.
Since the terms option and arguments are frequently used in different contexts we want to first clarify our usage:
-i myfile
, --infile myfile
] refer to key-value pairs. The key is either a short indentifier, restricted to a single character -i
, or a long identifier --infile
.arg1
] refers to command line arguments that are specified without an identifier/key, are always required and are identified by their position.-b
] refers to identifiers that are not followed by a value (booleans) and therefore only indicate whether they are set or not.Adding an option is done in a single call. You simply need to provide a predeclared variable and some additional information like the identifier, description or advanced restrictions. To actually retrieve the value from the command line and enable every other mechanism you need to call the seqan3::argument_parser::parse function in the end.
Now you can call your application via the command line:
You can also display the help page automatically:
There are two different kinds of errors: Developer errors and user errors.
Developer errors are those that violate the seqan3::argument_parser design (e.g. calling the seqan3::argument_parser::parse function twice or specifying two different options with the same identifier.) In this case, a seqan3::design_error is thrown.
The second kind are user errors, due to invalid command line calls. In this case a seqan3::argument_parser_error is thrown.
For example:
See the seqan3::argument_parser::parse documentation for a detailed list of which exceptions are caught.
SeqAn applications that are using the seqan3::argument_parser can check SeqAn servers for version updates. The functionality helps getting new versions out to users faster. It is also used to inform application developers of new versions of the SeqAn library which means that applications ship with less bugs. For privacy implications, please see: https://github.com/seqan/seqan3/wiki/Update-Notifications.
Users of applications that have this feature activated can opt-out, by either:
--version-check false/0
orSEQAN3_NO_VERSION_CHECK
environment variable.Note that in case there is no --version-check
option (display available options with -h/--help)
, then the developer already disabled the version check functionality.
seqan3::design_error | if this function was already called before. |
seqan3::option_declared_multiple_times | if an option that is not a list was declared multiple times. |
seqan3::user_input_error | if an incorrect argument is given as (positional) option value. |
seqan3::required_option_missing | if the user did not provide a required option. |
seqan3::too_many_arguments | if the command line call contained more arguments than expected. |
seqan3::too_few_arguments | if the command line call contained less arguments than expected. |
seqan3::validation_error | if the argument was not excepted by the provided validator. |
When no specific key words are supplied, the seqan3::argument_parser starts to process the command line for specified options, flags and positional options.
If the given command line input (argv
) contains the following keywords (in order of checking), the parser will exit (std::exit) with error code 0 after doing the following:
Example:
The code above gives the following output when calling --help
:
If the user does something wrong, it looks like this:
The SeqAn 3 Argument Parser offers a validation mechanism for (positional_)options via callables. You can pass any functor that fulfils the seqan3::validator and takes the value passed to the add_(positional_)option function call as a parameter. We provide some commonly used functor that might come in handy:
enum seqan3::option_spec |
Used to further specify argument_parser options/flags.
All options and flags are set to option_spec::standard unless specified otherwise by the developer, e.g. when calling argument_parser::add_option().
Enumerator | |
---|---|
standard | The default were no checking or special displaying is happening. |
required | Set an option as required if you want to enforce that the user supplies this option when calling the program via the command line. If the option is missing, the argument_parser will automatically detect this and throw a invalid_argument exception. |
advanced | Set an option/flag to advanced if you do not want the option to be displayed in the normal help page ( |
hidden | Set an option/flag to hidden, if you want to completely hide it from the user. It will never appear on the help page nor any export format. For example, this can be useful for debugging reasons. |
auto seqan3::operator| | ( | validator1_type && | vali1, |
validator2_type && | vali2 | ||
) |
Enables the chaining of validators.
validator1_type | The type of the fist validator; Must satisfy the seqan3::validator and the same option_value_type as the second validator type. |
validator2_type | The type of the second validator; Must satisfy the seqan3::validator and the same option_value_type as the fist validator type. |
[in] | vali1 | The first validator to chain. |
[in] | vali2 | The second validator to chain. |
The pipe operator is the AND operation for two validators, which means that a value must pass both validators in order to be accepted by the new validator.
For example you may want a file name that only accepts absolute paths but also must have one out of some given file extensions. For this purpose you can chain a seqan3::regex_validator to a seqan3::input_file_validator like this:
You can chain as many validators as you want which will be evaluated one after the other from left to right (first to last).
|
inline |
Return a conversion map from std::string_view to option_type.
your_type | Type of the value to retrieve the conversion map for. |
value | The value is not used, just its type. |
This is a function object. Invoke it with the parameter(s) specified above.
It acts as a wrapper and looks for two possible implementations (in this order):
enumeration_names
in seqan3::custom::argument_parsing<your_type>
that is of type std::unordered_map<std::string_view, your_type>>
.enumeration_names(your_type const a)
in the namespace of your type (or as friend
) which returns a std::unordered_map<std::string_view, your_type>>
.If you are working on a type in your own namespace, you should implement a free function like this:
Only if you cannot access the namespace of your type to customize you may specialize the seqan3::custom::argument_parsing struct like this:
This is a customisation point (see Customisation). To specify the behaviour for your own type, simply provide one of the two functions specified above.