1 #include <iostream>
2
3 #include <seqan/basic.h>
4 #include <seqan/sequence.h>
5 #include <seqan/stream.h> // For printing SeqAn Strings.
6
7 #include <seqan/arg_parse.h>
8
9 using namespace seqan;
10
main(int argc,char const ** argv)11 int main(int argc, char const ** argv)
12 {
13 // Initialize ArgumentParser.
14 ArgumentParser parser("arg_parse_demo");
15 setCategory(parser, "Demo");
16 setShortDescription(parser, "Just a demo of the new ArgumentParser!");
17 setVersion(parser, "0.1");
18 setDate(parser, "Mar 2012");
19
20 // Add use and description lines.
21 addUsageLine(parser, "[\\fIOPTIONS\\fP] \\fIIN\\fP \\fIOUT\\fP ");
22
23 addDescription(
24 parser,
25 "This is just a little demo to show what ArgumentParser is "
26 "able to do. \\fIIN\\fP is a multi-FASTA input file. \\fIOUT\\fP is a "
27 "txt output file.");
28
29 // Add positional arguments and set their valid file types.
30 addArgument(parser, ArgParseArgument(ArgParseArgument::INPUT_FILE, "IN"));
31 addArgument(parser, ArgParseArgument(ArgParseArgument::OUTPUT_FILE, "OUT"));
32 setValidValues(parser, 0, "FASTA fa");
33 setValidValues(parser, 1, "txt");
34
35 // Add a section with some options.
36 addSection(parser, "Important Tool Parameters");
37 addOption(parser, ArgParseOption("", "id", "Sequence identity between [0.0:1.0]",
38 ArgParseArgument::DOUBLE, "ID"));
39 setRequired(parser, "id", true);
40 setMinValue(parser, "id", "0.0");
41 setMaxValue(parser, "id", "1.0");
42
43 // Adding a verbose and a hidden option.
44 addSection(parser, "Miscellaneous");
45 addOption(parser, ArgParseOption("v", "verbose", "Turn on verbose output."));
46 addOption(parser, ArgParseOption("H", "hidden", "Super mysterious flag that will not be shown in "
47 "the help screen or man page."));
48 hideOption(parser, "H");
49
50 // Add a Reference section.
51 addTextSection(parser, "References");
52 addText(parser, "http://www.seqan.de");
53
54 // Parse the arguments.
55 ArgumentParser::ParseResult res = parse(parser, argc, argv);
56 // Return if there was an error or a built-in command was triggered (e.g. help).
57 if (res != ArgumentParser::PARSE_OK)
58 return res == ArgumentParser::PARSE_ERROR; // 1 on errors, 0 otherwise
59
60 // Extract and print the options.
61 bool verbose = false;
62 getOptionValue(verbose, parser, "verbose");
63 std::cout << "Verbose: " << (verbose ? "on" : "off") << std::endl;
64
65 double identity = -1.0;
66 getOptionValue(identity, parser, "id");
67 std::cout << "Identity: " << identity << std::endl;
68
69 CharString inputFile, outputFile;
70 getArgumentValue(inputFile, parser, 0);
71 getArgumentValue(outputFile, parser, 1);
72
73 std::cout << "Input-File: " << inputFile << std::endl;
74 std::cout << "Output-File: " << outputFile << std::endl;
75
76 return 0;
77 }
78