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 { |
| 32 | public: |
| 33 | Flags& requiredFlag(const StringPiece& name, const StringPiece& description, |
| 34 | std::string* value); |
| 35 | Flags& requiredFlagList(const StringPiece& name, const StringPiece& description, |
| 36 | std::vector<std::string>* value); |
| 37 | Flags& optionalFlag(const StringPiece& name, const StringPiece& description, |
| 38 | Maybe<std::string>* value); |
| 39 | Flags& optionalFlagList(const StringPiece& name, const StringPiece& description, |
| 40 | std::vector<std::string>* value); |
Adam Lesinski | 9756dec | 2016-08-08 12:35:04 -0700 | [diff] [blame^] | 41 | Flags& optionalFlagList(const StringPiece& name, const StringPiece& description, |
| 42 | std::unordered_set<std::string>* value); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 43 | Flags& optionalSwitch(const StringPiece& name, const StringPiece& description, |
| 44 | bool* value); |
| 45 | |
| 46 | void usage(const StringPiece& command, std::ostream* out); |
| 47 | |
| 48 | bool parse(const StringPiece& command, const std::vector<StringPiece>& args, |
| 49 | std::ostream* outError); |
| 50 | |
| 51 | const std::vector<std::string>& getArgs(); |
| 52 | |
| 53 | private: |
| 54 | struct Flag { |
| 55 | std::string name; |
| 56 | std::string description; |
| 57 | std::function<bool(const StringPiece& value)> action; |
| 58 | bool required; |
| 59 | size_t numArgs; |
| 60 | |
| 61 | bool parsed; |
| 62 | }; |
| 63 | |
| 64 | std::vector<Flag> mFlags; |
| 65 | std::vector<std::string> mArgs; |
| 66 | }; |
| 67 | |
| 68 | } // namespace aapt |
| 69 | |
| 70 | #endif // AAPT_FLAGS_H |