blob: 9feff6b4facaa42ac1859e27d63d3620a050d99e [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 Lesinskice5e56e2016-10-21 17:56:45 -070026#include "util/Maybe.h"
27#include "util/StringPiece.h"
28
Adam Lesinski1ab598f2015-08-14 14:26:04 -070029namespace aapt {
30
31class Flags {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070032 public:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070033 Flags& RequiredFlag(const StringPiece& name, const StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070034 std::string* value);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070035 Flags& RequiredFlagList(const StringPiece& name,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070036 const StringPiece& description,
37 std::vector<std::string>* value);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070038 Flags& OptionalFlag(const StringPiece& name, const StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070039 Maybe<std::string>* value);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070040 Flags& OptionalFlagList(const StringPiece& name,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070041 const StringPiece& description,
42 std::vector<std::string>* value);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070043 Flags& OptionalFlagList(const StringPiece& name,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070044 const StringPiece& description,
45 std::unordered_set<std::string>* value);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070046 Flags& OptionalSwitch(const StringPiece& name, const StringPiece& description,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070047 bool* value);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070048
Adam Lesinskice5e56e2016-10-21 17:56:45 -070049 void Usage(const StringPiece& command, std::ostream* out);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070050
Adam Lesinskice5e56e2016-10-21 17:56:45 -070051 bool Parse(const StringPiece& command, const std::vector<StringPiece>& args,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070052 std::ostream* outError);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070053
Adam Lesinskice5e56e2016-10-21 17:56:45 -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;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070062 size_t num_args;
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 Lesinskice5e56e2016-10-21 17:56:45 -070067 std::vector<Flag> flags_;
68 std::vector<std::string> args_;
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