From d13fb249865703901b77f48c5fed1864f06e1c63 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 12 May 2015 20:40:48 -0700 Subject: AAPT2: Debug: Dump only targetted style Change-Id: Id7c5a4b5d0880520e1fea05e5a31d398946c5f05 --- tools/aapt2/Flag.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'tools/aapt2/Flag.cpp') 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 action; + std::function action; bool required; bool* flagResult; bool flagValueWhenSet; @@ -23,22 +23,38 @@ struct Flag { static std::vector sFlags; static std::vector sArgs; +static std::function wrap( + const std::function& action) { + return [action](const StringPiece& arg, std::string*) -> bool { + action(arg); + return true; + }; +} + void optionalFlag(const StringPiece& name, const StringPiece& description, std::function 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 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 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; } -- cgit v1.2.3-59-g8ed1b