-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Enum support for the argument parser.
- Loading branch information
1 parent
0768d4b
commit dbca685
Showing
8 changed files
with
411 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <seqan3/argument_parser/all.hpp> | ||
|
||
namespace your_namespace | ||
{ | ||
|
||
enum class Foo | ||
{ | ||
one, | ||
two, | ||
three | ||
}; | ||
|
||
// specialise a mapping from your values of type Foo to the respective string | ||
auto string_conversion_map(Foo) | ||
{ | ||
return std::unordered_map<std::string, Foo>{{{"one", Foo::one}, {"two", Foo::two}, {"three", Foo::three}}}; | ||
} | ||
|
||
} // namespace your_namespace | ||
|
||
|
||
int main(int argc, char const * argv[]) | ||
{ | ||
your_namespace::Foo value{}; | ||
|
||
seqan3::argument_parser parser{"my_program", argc, argv}; | ||
|
||
// Because of the string_conversion_map function | ||
// you can now add an option that takes a value of type Foo: | ||
parser.add_option(value, 'f', "foo", "Give me a value foo value."); | ||
|
||
try | ||
{ | ||
parser.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; | ||
} | ||
} |
Oops, something went wrong.