Skip to content

Commit a094c8e

Browse files
committed
Move HaveHelpFlag out of flag_parser
It's only used by the cvd command, so moved it there.
1 parent 44b766b commit a094c8e

7 files changed

Lines changed: 38 additions & 37 deletions

File tree

base/cvd/cuttlefish/flag_parser/flag_parser.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ namespace cuttlefish {
4949

5050
namespace {
5151

52-
/*
53-
* From external/gflags/src, commit:
54-
* 061f68cd158fa658ec0b9b2b989ed55764870047
55-
*
56-
*/
57-
constexpr std::array help_bool_opts{
58-
"help", "helpfull", "helpshort", "helppackage", "helpxml", "version", "h"};
59-
constexpr std::array help_str_opts{
60-
"helpon",
61-
"helpmatch",
62-
};
63-
6452
bool ShouldBeNullOpt(std::string_view value, CoerceToNullopt opt) {
6553
switch (opt) {
6654
case CoerceToNullopt::None:
@@ -780,21 +768,4 @@ Flag GflagsCompatFlag(const std::string& name,
780768
return GflagsCompatFlagImpl(name, value, opt);
781769
}
782770

783-
Result<bool> HasHelpFlag(const std::vector<std::string>& args) {
784-
std::vector<std::string> copied_args(args);
785-
std::vector<Flag> flags;
786-
flags.reserve(help_bool_opts.size() + help_str_opts.size());
787-
bool bool_value_placeholder = false;
788-
std::string str_value_placeholder;
789-
for (const auto bool_opt : help_bool_opts) {
790-
flags.emplace_back(GflagsCompatFlag(bool_opt, bool_value_placeholder));
791-
}
792-
for (const auto str_opt : help_str_opts) {
793-
flags.emplace_back(GflagsCompatFlag(str_opt, str_value_placeholder));
794-
}
795-
CF_EXPECT(ConsumeFlags(flags, copied_args));
796-
// if there was any match, some in copied_args were consumed.
797-
return (args.size() != copied_args.size());
798-
}
799-
800771
} // namespace cuttlefish

base/cvd/cuttlefish/flag_parser/flag_parser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,5 @@ Flag GflagsCompatFlag(
220220
const std::string& name, std::optional<std::vector<unsigned>>& value,
221221
CoerceToNullopt opt = CoerceToNullopt::None);
222222

223-
// e.g. cvd start --help, cvd stop -help, cvd fleet -h
224-
Result<bool> HasHelpFlag(const std::vector<std::string>& args);
225223

226224
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/cvd/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ cf_cc_library(
1212
copts = COPTS + ["-Werror=sign-compare"],
1313
deps = [
1414
"//cuttlefish/common/libs/utils:environment",
15-
"//cuttlefish/flag_parser",
1615
"//cuttlefish/host/commands/cvd/cli:command_request",
1716
"//cuttlefish/host/commands/cvd/cli:frontline_parser",
1817
"//cuttlefish/host/commands/cvd/cli:nesting_commands",
@@ -33,9 +32,9 @@ cf_cc_binary(
3332
":libcvd",
3433
"//cuttlefish/common/libs/utils:environment",
3534
"//cuttlefish/common/libs/utils:files",
36-
"//cuttlefish/flag_parser",
3735
"//cuttlefish/common/libs/utils:subprocess",
3836
"//cuttlefish/common/libs/utils:tee_logging",
37+
"//cuttlefish/flag_parser",
3938
"//cuttlefish/host/commands/cvd/cli:log_files",
4039
"//cuttlefish/host/commands/cvd/utils",
4140
"//cuttlefish/host/commands/cvd/version",

base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ cf_cc_library(
112112
"//cuttlefish/common/libs/utils:contains",
113113
"//cuttlefish/common/libs/utils:environment",
114114
"//cuttlefish/common/libs/utils:files",
115-
"//cuttlefish/flag_parser",
116115
"//cuttlefish/common/libs/utils:subprocess",
117116
"//cuttlefish/common/libs/utils:users",
117+
"//cuttlefish/flag_parser",
118118
"//cuttlefish/host/commands/cvd/cli:command_request",
119119
"//cuttlefish/host/commands/cvd/cli:help_format",
120120
"//cuttlefish/host/commands/cvd/cli:types",
@@ -183,11 +183,11 @@ cf_cc_library(
183183
"//cuttlefish/common/libs/fs",
184184
"//cuttlefish/common/libs/utils:contains",
185185
"//cuttlefish/common/libs/utils:files",
186-
"//cuttlefish/flag_parser",
187186
"//cuttlefish/common/libs/utils:gflags_xml_parser",
188187
"//cuttlefish/common/libs/utils:subprocess",
189188
"//cuttlefish/common/libs/utils:subprocess_managed_stdio",
190189
"//cuttlefish/common/libs/utils:users",
190+
"//cuttlefish/flag_parser",
191191
"//cuttlefish/host/commands/cvd/instances:config_path",
192192
"//cuttlefish/host/commands/cvd/utils",
193193
"//cuttlefish/host/libs/config:config_constants",

base/cvd/cuttlefish/host/commands/cvd/cli/command_request.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,27 @@
2323

2424
#include <android-base/file.h>
2525

26-
#include "cuttlefish/flag_parser/flag_parser.h"
2726
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
2827
#include "cuttlefish/host/commands/cvd/cli/selector/selector_common_parser.h"
2928
#include "cuttlefish/result/result.h"
3029

3130
namespace cuttlefish {
3231

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
3347
CommandRequest::CommandRequest(cvd_common::Args args, cvd_common::Envs env,
3448
selector::SelectorOptions selectors)
3549
: args_(std::move(args)),
@@ -93,4 +107,21 @@ Result<CommandRequest> CommandRequestBuilder::Build() && {
93107
std::move(selector_options_));
94108
}
95109

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+
96127
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/cvd/cli/command_request.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,7 @@ class CommandRequestBuilder {
105105
selector::SelectorOptions selector_options_;
106106
};
107107

108+
// e.g. cvd start --help, cvd stop -help, cvd fleet -h
109+
Result<bool> HasHelpFlag(const std::vector<std::string>& args);
110+
108111
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/cvd/cvd.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <unordered_map>
2222
#include <vector>
2323

24-
#include "cuttlefish/flag_parser/flag_parser.h"
2524
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
2625
#include "cuttlefish/host/commands/cvd/cli/frontline_parser.h"
2726
#include "cuttlefish/host/commands/cvd/cli/request_context.h"

0 commit comments

Comments
 (0)