Skip to content

Commit

Permalink
Using nicer format for transform
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Nov 24, 2017
1 parent c8380d6 commit 8215ec7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
7 changes: 5 additions & 2 deletions include/CLI/Option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ class Option : public OptionBase<Option> {
}

/// Adds a validator-like function that can change result
Option *transform(std::function<bool(std::string &)> validator) {
validators_.push_back(validator);
Option *transform(std::function<std::string(std::string)> func) {
validators_.push_back([func](std::string &inout) {
inout = func(inout);
return true;
});
return this;
}

Expand Down
10 changes: 2 additions & 8 deletions tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,14 +1176,8 @@ TEST_F(TApp, SetWithDefaultsIC) {
TEST_F(TApp, OrderedModifingValidators) {
std::vector<std::string> val;
auto m = app.add_option("-m", val);
m->transform([](std::string &x) {
x += "1";
return true;
});
m->transform([](std::string &x) {
x += "2";
return true;
});
m->transform([](std::string x) { return x + "1"; });
m->transform([](std::string x) { return x + "2"; });

args = {"-mone", "-mtwo"};

Expand Down

0 comments on commit 8215ec7

Please sign in to comment.