|
23 | 23 |
|
24 | 24 | #include <android-base/file.h> |
25 | 25 |
|
26 | | -#include "cuttlefish/flag_parser/flag_parser.h" |
27 | 26 | #include "cuttlefish/host/commands/cvd/cli/command_request.h" |
28 | 27 | #include "cuttlefish/host/commands/cvd/cli/selector/selector_common_parser.h" |
29 | 28 | #include "cuttlefish/result/result.h" |
30 | 29 |
|
31 | 30 | namespace cuttlefish { |
32 | 31 |
|
| 32 | +namespace { |
| 33 | + |
| 34 | +/* |
| 35 | + * From external/gflags/src, commit: |
| 36 | + * 061f68cd158fa658ec0b9b2b989ed55764870047 |
| 37 | + * |
| 38 | + */ |
| 39 | +constexpr std::array help_bool_opts{ |
| 40 | + "help", "helpfull", "helpshort", "helppackage", "helpxml", "version", "h"}; |
| 41 | +constexpr std::array help_str_opts{ |
| 42 | + "helpon", |
| 43 | + "helpmatch", |
| 44 | +}; |
| 45 | + |
| 46 | +} // namespace |
33 | 47 | CommandRequest::CommandRequest(cvd_common::Args args, cvd_common::Envs env, |
34 | 48 | selector::SelectorOptions selectors) |
35 | 49 | : args_(std::move(args)), |
@@ -93,4 +107,21 @@ Result<CommandRequest> CommandRequestBuilder::Build() && { |
93 | 107 | std::move(selector_options_)); |
94 | 108 | } |
95 | 109 |
|
| 110 | +Result<bool> HasHelpFlag(const std::vector<std::string>& args) { |
| 111 | + std::vector<std::string> copied_args(args); |
| 112 | + std::vector<Flag> flags; |
| 113 | + flags.reserve(help_bool_opts.size() + help_str_opts.size()); |
| 114 | + bool bool_value_placeholder = false; |
| 115 | + std::string str_value_placeholder; |
| 116 | + for (const auto bool_opt : help_bool_opts) { |
| 117 | + flags.emplace_back(GflagsCompatFlag(bool_opt, bool_value_placeholder)); |
| 118 | + } |
| 119 | + for (const auto str_opt : help_str_opts) { |
| 120 | + flags.emplace_back(GflagsCompatFlag(str_opt, str_value_placeholder)); |
| 121 | + } |
| 122 | + CF_EXPECT(ConsumeFlags(flags, copied_args)); |
| 123 | + // if there was any match, some in copied_args were consumed. |
| 124 | + return (args.size() != copied_args.size()); |
| 125 | +} |
| 126 | + |
96 | 127 | } // namespace cuttlefish |
0 commit comments