blob: 3b3ae710dc7b095e2d21c76e4fb848af257d15ee [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
Adam Lesinski1ab598f2015-08-14 14:26:04 -070020#include <functional>
21#include <ostream>
22#include <string>
Adam Lesinski9756dec2016-08-08 12:35:04 -070023#include <unordered_set>
Adam Lesinski1ab598f2015-08-14 14:26:04 -070024#include <vector>
25
Adam Lesinskid5083f62017-01-16 15:07:21 -080026#include "androidfw/StringPiece.h"
27
Adam Lesinskice5e56e2016-10-21 17:56:45 -070028#include "util/Maybe.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070029
Adam Lesinski1ab598f2015-08-14 14:26:04 -070030namespace aapt {
31
32class Flags {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070033 public:
Adam Lesinskid5083f62017-01-16 15:07:21 -080034 Flags& RequiredFlag(const android::StringPiece& name, const android::StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070035 std::string* value);
Adam Lesinskid5083f62017-01-16 15:07:21 -080036 Flags& RequiredFlagList(const android::StringPiece& name, const android::StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070037 std::vector<std::string>* value);
Adam Lesinskid5083f62017-01-16 15:07:21 -080038 Flags& OptionalFlag(const android::StringPiece& name, const android::StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070039 Maybe<std::string>* value);
Adam Lesinskid5083f62017-01-16 15:07:21 -080040 Flags& OptionalFlagList(const android::StringPiece& name, const android::StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070041 std::vector<std::string>* value);
Adam Lesinskid5083f62017-01-16 15:07:21 -080042 Flags& OptionalFlagList(const android::StringPiece& name, const android::StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070043 std::unordered_set<std::string>* value);
Adam Lesinskid5083f62017-01-16 15:07:21 -080044 Flags& OptionalSwitch(const android::StringPiece& name, const android::StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070045 bool* value);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070046
Adam Lesinskid5083f62017-01-16 15:07:21 -080047 void Usage(const android::StringPiece& command, std::ostream* out);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070048
Adam Lesinskid5083f62017-01-16 15:07:21 -080049 bool Parse(const android::StringPiece& command, const std::vector<android::StringPiece>& args,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070050 std::ostream* outError);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070051
Adam Lesinskice5e56e2016-10-21 17:56:45 -070052 const std::vector<std::string>& GetArgs();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070053
Adam Lesinskicacb28f2016-10-19 12:18:14 -070054 private:
55 struct Flag {
56 std::string name;
57 std::string description;
Adam Lesinskid5083f62017-01-16 15:07:21 -080058 std::function<bool(const android::StringPiece& value)> action;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070059 bool required;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070060 size_t num_args;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070061
Adam Lesinskicacb28f2016-10-19 12:18:14 -070062 bool parsed;
63 };
Adam Lesinski1ab598f2015-08-14 14:26:04 -070064
Adam Lesinskice5e56e2016-10-21 17:56:45 -070065 std::vector<Flag> flags_;
66 std::vector<std::string> args_;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070067};
68
Adam Lesinskicacb28f2016-10-19 12:18:14 -070069} // namespace aapt
Adam Lesinski1ab598f2015-08-14 14:26:04 -070070
Adam Lesinskicacb28f2016-10-19 12:18:14 -070071#endif // AAPT_FLAGS_H