-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding map support to IsMember (#228)
* Adding first draft of mapping * IsMember now supports maps * Adding example, better Val combs, and cleanup * Reversing order of map, adding pair support * Check/Transform suppport for Validators * Adding enum tools from @phlptp, more tests
- Loading branch information
Showing
10 changed files
with
290 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
#include <CLI/CLI.hpp> | ||
#include <map> | ||
#include <sstream> | ||
|
||
enum class Level : int { High, Medium, Low }; | ||
|
||
std::istream &operator>>(std::istream &in, Level &level) { | ||
int i; | ||
in >> i; | ||
level = static_cast<Level>(i); | ||
return in; | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &in, const Level &level) { return in << static_cast<int>(level); } | ||
|
||
int main(int argc, char **argv) { | ||
CLI::App app; | ||
|
||
std::map<std::string, Level> map = {{"High", Level::High}, {"Medium", Level::Medium}, {"Low", Level::Low}}; | ||
|
||
Level level; | ||
|
||
app.add_option("-l,--level", level, "Level settings") | ||
->check(CLI::IsMember({Level::High, Level::Medium, Level::Low})) | ||
->type_name("enum/Level in {High=0, Medium=1, Low=2}"); | ||
->required() | ||
->transform(CLI::IsMember(map, CLI::ignore_case) | CLI::IsMember({Level::High, Level::Medium, Level::Low})); | ||
|
||
CLI11_PARSE(app, argc, argv); | ||
|
||
// CLI11's built in enum streaming can be used outside CLI11 like this: | ||
using namespace CLI::enums; | ||
std::cout << "Enum received: " << level << std::endl; | ||
|
||
return 0; | ||
} |
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
Oops, something went wrong.