Loading...
Searching...
No Matches
seqan3::custom::argument_parsing< t > Struct Template Reference
Argument Parser

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...

`#include <seqan3/argument_parser/auxiliary.hpp>`

## Detailed Description

template<typename t>
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.

Template Parameters

  t | The type you wish to specialise for.

### Named Enumerations

In order to use a third party type within the seqan3::argument_parser::add_option or seqan3::argument_parser::add_positional_option call, you can specialise this struct in the following way:

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <ranges>
#include <system_error>
#include <seqan3/argument_parser/all.hpp>
namespace seqan3::custom
{
// Specialise the seqan3::custom::argument_parsing data structure to enable parsing of std::errc.
template <>
struct argument_parsing<std::errc>
{
// Specialise a mapping from an identifying string to the respective value of your type Foo.
static inline std::unordered_map<std::string_view, std::errc> const enumeration_names{
{"no_error", std::errc{}},
{"timed_out", std::errc::timed_out},
{"invalid_argument", std::errc::invalid_argument},
{"io_error", std::errc::io_error}};
};
} // namespace seqan3::custom
int main(int argc, char const * argv[])
{
std::errc value{};
seqan3::argument_parser parser{"my_program", argc, argv};
// Because of the argument_parsing struct and
// the static member function enumeration_names
// you can now add an option that takes a value of type std::errc:
parser.add_option(value,
'e',
"errc",
"Give me a std::errc value.",
seqan3::option_spec::standard,
seqan3::value_list_validator{(seqan3::enumeration_names<std::errc> | std::views::values)});
try
{
parser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
return 0;
}
all.hpp
Meta-header for the Argument Parser module .
std::cerr
seqan3::argument_parser_error
Argument parser exception that is thrown whenever there is an error while parsing the command line ar...
Definition exceptions.hpp:39
seqan3::argument_parser
The SeqAn command line parser.
Definition argument_parser.hpp:147
seqan3::argument_parser::add_option
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:238
seqan3::argument_parser::parse
void parse()
Initiates the actual command line parsing.
Definition argument_parser.hpp:404
seqan3::value_list_validator
A validator that checks whether a value is inside a list of valid values.
Definition validators.hpp:199
std::errc
seqan3::enumeration_names
auto const enumeration_names
Return a conversion map from std::string_view to option_type.
Definition auxiliary.hpp:162
seqan3::standard
@ standard
The default were no checking or special displaying is happening.
Definition auxiliary.hpp:250
seqan3::custom
A namespace for third party and standard library specialisations of SeqAn customisation points.
Definition char.hpp:40
std
SeqAn specific customisations in the standard namespace.
seqan3::custom::argument_parsing
A type that can be specialised to provide customisation point implementations for the seqan3::argumen...
Definition auxiliary.hpp:51
system_error
std::unordered_map
std::runtime_error::what
T what(T... args)

Please note that by default the t const, t & and t const & specialisations of this class inherit the specialisation for t so you usually only need to provide a specialisation for t.

Note
  Only use this if you cannot provide respective functions in your namespace. See the tutorial Parsing command line arguments with Sharg for an example of customising a type within your own namespace.

Remarks
  For a complete overview, take a look at Argument Parser

The documentation for this struct was generated from the following file:

- auxiliary.hpp

Hide me