diff options
| author | 2015-05-13 21:41:38 +0000 | |
|---|---|---|
| committer | 2015-05-13 21:41:47 +0000 | |
| commit | 45fefaef008c16af42256fb2d8eab183245d030d (patch) | |
| tree | 090879c6100951f81cd7c9345ac73a0347694e6e /tools/aapt2/Flag.cpp | |
| parent | 68727a0b2074d6a9c03cff967c28da069deedae3 (diff) | |
| parent | d13fb249865703901b77f48c5fed1864f06e1c63 (diff) | |
Merge "AAPT2: Debug: Dump only targetted style" into mnc-dev
Diffstat (limited to 'tools/aapt2/Flag.cpp')
| -rw-r--r-- | tools/aapt2/Flag.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/tools/aapt2/Flag.cpp b/tools/aapt2/Flag.cpp index 0f63c2c44887..76985da99912 100644 --- a/tools/aapt2/Flag.cpp +++ b/tools/aapt2/Flag.cpp @@ -13,7 +13,7 @@ namespace flag { struct Flag { std::string name; std::string description; - std::function<void(const StringPiece&)> action; + std::function<bool(const StringPiece&, std::string*)> action; bool required; bool* flagResult; bool flagValueWhenSet; @@ -23,22 +23,38 @@ struct Flag { static std::vector<Flag> sFlags; static std::vector<std::string> sArgs; +static std::function<bool(const StringPiece&, std::string*)> wrap( + const std::function<void(const StringPiece&)>& action) { + return [action](const StringPiece& arg, std::string*) -> bool { + action(arg); + return true; + }; +} + void optionalFlag(const StringPiece& name, const StringPiece& description, std::function<void(const StringPiece&)> action) { - sFlags.push_back( - Flag{ name.toString(), description.toString(), action, false, nullptr, false, false }); + sFlags.push_back(Flag{ + name.toString(), description.toString(), wrap(action), + false, nullptr, false, false }); } void requiredFlag(const StringPiece& name, const StringPiece& description, std::function<void(const StringPiece&)> action) { - sFlags.push_back( - Flag{ name.toString(), description.toString(), action, true, nullptr, false, false }); + sFlags.push_back(Flag{ name.toString(), description.toString(), wrap(action), + true, nullptr, false, false }); +} + +void requiredFlag(const StringPiece& name, const StringPiece& description, + std::function<bool(const StringPiece&, std::string*)> action) { + sFlags.push_back(Flag{ name.toString(), description.toString(), action, + true, nullptr, false, false }); } void optionalSwitch(const StringPiece& name, const StringPiece& description, bool resultWhenSet, bool* result) { sFlags.push_back(Flag{ - name.toString(), description.toString(), {}, false, result, resultWhenSet, false }); + name.toString(), description.toString(), {}, + false, result, resultWhenSet, false }); } void usageAndDie(const StringPiece& command) { @@ -62,6 +78,7 @@ void usageAndDie(const StringPiece& command) { } void parse(int argc, char** argv, const StringPiece& command) { + std::string errorStr; for (int i = 0; i < argc; i++) { const StringPiece arg(argv[i]); if (*arg.data() != '-') { @@ -83,7 +100,11 @@ void parse(int argc, char** argv, const StringPiece& command) { << std::endl; usageAndDie(command); } - flag.action(argv[i]); + + if (!flag.action(argv[i], &errorStr)) { + std::cerr << errorStr << "." << std::endl << std::endl; + usageAndDie(command); + } } break; } |