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 <functional>
21#include <ostream>
22#include <string>
23#include <unordered_set>
24#include <vector>
25
26#include "androidfw/StringPiece.h"
27
28#include "util/Maybe.h"
29
30namespace aapt {
31
32class Flags {
33 public:
34  Flags& RequiredFlag(const android::StringPiece& name, const android::StringPiece& description,
35                      std::string* value);
36  Flags& RequiredFlagList(const android::StringPiece& name, const android::StringPiece& description,
37                          std::vector<std::string>* value);
38  Flags& OptionalFlag(const android::StringPiece& name, const android::StringPiece& description,
39                      Maybe<std::string>* value);
40  Flags& OptionalFlagList(const android::StringPiece& name, const android::StringPiece& description,
41                          std::vector<std::string>* value);
42  Flags& OptionalFlagList(const android::StringPiece& name, const android::StringPiece& description,
43                          std::unordered_set<std::string>* value);
44  Flags& OptionalSwitch(const android::StringPiece& name, const android::StringPiece& description,
45                        bool* value);
46
47  void Usage(const android::StringPiece& command, std::ostream* out);
48
49  bool Parse(const android::StringPiece& command, const std::vector<android::StringPiece>& args,
50             std::ostream* outError);
51
52  const std::vector<std::string>& GetArgs();
53
54 private:
55  struct Flag {
56    std::string name;
57    std::string description;
58    std::function<bool(const android::StringPiece& value)> action;
59    bool required;
60    size_t num_args;
61
62    bool parsed;
63  };
64
65  std::vector<Flag> flags_;
66  std::vector<std::string> args_;
67};
68
69}  // namespace aapt
70
71#endif  // AAPT_FLAGS_H
72