SeqAn3
seqan3::file_existance_validator Class Reference

A validator that checks if a file exists. More...

#include <seqan3/argument_parser/validators.hpp>

Public Types

using value_type = filesystem::path
 Type of values that are tested by validator.
 

Public Member Functions

std::string get_help_page_message () const
 Returns a message that can be appended to the (positional) options help page info.
 
void operator() (filesystem::path const &path) const
 Tests whether path exists. More...
 
void operator() (std::vector< filesystem::path > const &v) const
 Tests whether every filename in list v exists.
 

Detailed Description

A validator that checks if a file exists.

The struct then acts as a functor that throws a seqan3::parser_invalid_argument exception whenever a given filename (string) does not exist.

int main(int argc, const char ** argv)
{
seqan3::argument_parser myparser("Test", argc, argv); // initialize
seqan3::filesystem::path myfile;
myparser.add_option(myfile,'f',"file","Give me a filename.",
// an exception will be thrown if the user specifies a filename that does not exist
try
{
myparser.parse();
}
catch (seqan3::parser_invalid_argument const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
catch (seqan3::parser_interruption const &) // expected behaviour on special requests (e.g. `--help`)
{
return 0;
}
seqan3::debug_stream << "filename given by user passed validation: " << myfile.string() << "\n";
return 0;
}

Member Function Documentation

◆ operator()()

void seqan3::file_existance_validator::operator() ( filesystem::path const &  path) const
inline

Tests whether path exists.

Parameters
pathThe input value to check.
Exceptions
parser_invalid_argument

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