blob: 4a0efdb5b3785018f45cfdf7ddcdb4f797690732 [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
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 Lesinski9756dec2016-08-08 12:35:04 -070026#include <unordered_set>
Adam Lesinski1ab598f2015-08-14 14:26:04 -070027#include <vector>
28
29namespace aapt {
30
31class Flags {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070032 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 Lesinski1ab598f2015-08-14 14:26:04 -070048
Adam Lesinskicacb28f2016-10-19 12:18:14 -070049 void usage(const StringPiece& command, std::ostream* out);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070050
Adam Lesinskicacb28f2016-10-19 12:18:14 -070051 bool parse(const StringPiece& command, const std::vector<StringPiece>& args,
52 std::ostream* outError);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070053
Adam Lesinskicacb28f2016-10-19 12:18:14 -070054 const std::vector<std::string>& getArgs();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070055
Adam Lesinskicacb28f2016-10-19 12:18:14 -070056 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 Lesinski1ab598f2015-08-14 14:26:04 -070063
Adam Lesinskicacb28f2016-10-19 12:18:14 -070064 bool parsed;
65 };
Adam Lesinski1ab598f2015-08-14 14:26:04 -070066
Adam Lesinskicacb28f2016-10-19 12:18:14 -070067 std::vector<Flag> mFlags;
68 std::vector<std::string> mArgs;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070069};
70
Adam Lesinskicacb28f2016-10-19 12:18:14 -070071} // namespace aapt
Adam Lesinski1ab598f2015-08-14 14:26:04 -070072
Adam Lesinskicacb28f2016-10-19 12:18:14 -070073#endif // AAPT_FLAGS_H