| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_COMMAND_H |
| 18 |
#define AAPT_COMMAND_H |
| 19 |
|
| 20 |
#include <functional> |
| •21 |
#include <memory> |
| 22 |
#include <optional> |
| 23 |
#include <ostream> |
| 24 |
#include <string> |
| 25 |
#include <unordered_set> |
| 26 |
#include <vector> |
| 27 |
|
| 28 |
#include "androidfw/StringPiece.h" |
| 29 |
|
| 30 |
namespace aapt { |
| 31 |
|
| 32 |
class Command { |
| 33 |
public: |
| 34 |
explicit Command(const android::StringPiece& name) |
| 35 |
: name_(name.to_string()), full_subcommand_name_(name.to_string()){}; |
| 36 |
|
| 37 |
explicit Command(const android::StringPiece& name, const android::StringPiece& short_name) |
| 38 |
: name_(name.to_string()), |
| 39 |
short_name_(short_name.to_string()), |
| 40 |
full_subcommand_name_(name.to_string()){}; |
| 41 |
|
| 42 |
Command(Command&&) = default; |
| 43 |
Command& operator=(Command&&) = default; |
| 44 |
|
| 45 |
virtual ~Command() = default; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
enum : uint32_t { |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
kPath = 1 << 0, |
| 54 |
}; |
| 55 |
|
| 56 |
void AddRequiredFlag(const android::StringPiece& name, const android::StringPiece& description, |
| 57 |
std::string* value, uint32_t flags = 0); |
| 58 |
|
| 59 |
void AddRequiredFlagList(const android::StringPiece& name, |
| 60 |
const android::StringPiece& description, std::vector<std::string>* value, |
| 61 |
uint32_t flags = 0); |
| 62 |
|
| 63 |
void AddOptionalFlag(const android::StringPiece& name, const android::StringPiece& description, |
| 64 |
std::optional<std::string>* value, uint32_t flags = 0); |
| 65 |
|
| 66 |
void AddOptionalFlagList(const android::StringPiece& name, |
| 67 |
const android::StringPiece& description, std::vector<std::string>* value, |
| 68 |
uint32_t flags = 0); |
| 69 |
|
| 70 |
void AddOptionalFlagList(const android::StringPiece& name, |
| 71 |
const android::StringPiece& description, |
| 72 |
std::unordered_set<std::string>* value); |
| 73 |
|
| 74 |
void AddOptionalSwitch(const android::StringPiece& name, const android::StringPiece& description, |
| 75 |
bool* value); |
| 76 |
|
| 77 |
void AddOptionalSubcommand(std::unique_ptr<Command>&& subcommand, bool experimental = false); |
| 78 |
|
| 79 |
void SetDescription(const android::StringPiece& name); |
| 80 |
|
| 81 |
|
| 82 |
void Usage(std::ostream* out); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
int Execute(const std::vector<android::StringPiece>& args, std::ostream* outError); |
| 88 |
|
| 89 |
|
| 90 |
virtual int Action(const std::vector<std::string>& args) = 0; |
| 91 |
|
| 92 |
private: |
| 93 |
struct Flag { |
| 94 |
explicit Flag(const android::StringPiece& name, const android::StringPiece& description, |
| 95 |
const bool is_required, const size_t num_args, |
| 96 |
std::function<bool(const android::StringPiece& value)>&& action) |
| 97 |
: name(name.to_string()), description(description.to_string()), is_required(is_required), |
| 98 |
num_args(num_args), action(std::move(action)) {} |
| 99 |
|
| 100 |
const std::string name; |
| 101 |
const std::string description; |
| 102 |
const bool is_required; |
| 103 |
const size_t num_args; |
| 104 |
const std::function<bool(const android::StringPiece& value)> action; |
| 105 |
bool found = false; |
| 106 |
}; |
| 107 |
|
| 108 |
std::string name_; |
| 109 |
std::string short_name_; |
| 110 |
std::string description_ = ""; |
| 111 |
std::string full_subcommand_name_; |
| 112 |
|
| 113 |
std::vector<Flag> flags_; |
| 114 |
std::vector<std::unique_ptr<Command>> subcommands_; |
| 115 |
std::vector<std::unique_ptr<Command>> experimental_subcommands_; |
| 116 |
}; |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
#endif |