Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef AAPT_FLAGS_H |
| 18 | #define AAPT_FLAGS_H |
| 19 | |
| 20 | #include "util/Maybe.h" |
| 21 | #include "util/StringPiece.h" |
| 22 | |
| 23 | #include <functional> |
| 24 | #include <ostream> |
| 25 | #include <string> |
Adam Lesinski | 9756dec | 2016-08-08 12:35:04 -0700 | [diff] [blame] | 26 | #include <unordered_set> |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 27 | #include <vector> |
| 28 | |
| 29 | namespace aapt { |
| 30 | |
| 31 | class Flags { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 32 | public: |
| 33 | Flags& requiredFlag(const StringPiece& name, const StringPiece& description, |
| 34 | std::string* value); |
| 35 | Flags& requiredFlagList(const StringPiece& name, |
| 36 | const StringPiece& description, |
| 37 | std::vector<std::string>* value); |
| 38 | Flags& optionalFlag(const StringPiece& name, const StringPiece& description, |
| 39 | Maybe<std::string>* value); |
| 40 | Flags& optionalFlagList(const StringPiece& name, |
| 41 | const StringPiece& description, |
| 42 | std::vector<std::string>* value); |
| 43 | Flags& optionalFlagList(const StringPiece& name, |
| 44 | const StringPiece& description, |
| 45 | std::unordered_set<std::string>* value); |
| 46 | Flags& optionalSwitch(const StringPiece& name, const StringPiece& description, |
| 47 | bool* value); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 48 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 49 | void usage(const StringPiece& command, std::ostream* out); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 50 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 51 | bool parse(const StringPiece& command, const std::vector<StringPiece>& args, |
| 52 | std::ostream* outError); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 53 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 54 | const std::vector<std::string>& getArgs(); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 55 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 56 | private: |
| 57 | struct Flag { |
| 58 | std::string name; |
| 59 | std::string description; |
| 60 | std::function<bool(const StringPiece& value)> action; |
| 61 | bool required; |
| 62 | size_t numArgs; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 63 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 64 | bool parsed; |
| 65 | }; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 66 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 67 | std::vector<Flag> mFlags; |
| 68 | std::vector<std::string> mArgs; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 71 | } // namespace aapt |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 72 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 73 | #endif // AAPT_FLAGS_H |