File: introduction_argument_parser.cpp

package info (click to toggle)
seqan3 3.0.2%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,052 kB
  • sloc: cpp: 144,641; makefile: 1,288; ansic: 294; sh: 228; xml: 217; javascript: 50; python: 27; php: 25
file content (27 lines) | stat: -rw-r--r-- 829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! [argparse]
#include <string>                         // for std::string
#include <seqan3/argument_parser/all.hpp> // for argument_parser
#include <seqan3/core/debug_stream.hpp>   // for debug_stream

int main(int argc, char * argv[])
{
    // Create a buffer for the input.
    std::string input{};
    // Initialise the Argument Parser and add an option.
    seqan3::argument_parser parser("My-first-program", argc, argv);
    parser.add_positional_option(input, "Give me text.");

    // Parse the given arguments and catch possible errors.
    try
    {
        parser.parse();
    }
    catch (seqan3::argument_parser_error const & ext)
    {
        seqan3::debug_stream << "[PARSER ERROR] " << ext.what() << '\n';
        return 0;
    }

    seqan3::debug_stream << "The text was: " << input << "\n";
}
//! [argparse]