Skip to content

Commit fcea51c

Browse files
committed
Fail with unsupported flags.
Bug: b/329890155
1 parent a498b9c commit fcea51c

12 files changed

Lines changed: 26 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ cf_cc_library(
6666
srcs = ["clear.cpp"],
6767
hdrs = ["clear.h"],
6868
deps = [
69+
"//cuttlefish/common/libs/utils:flag_parser",
6970
"//cuttlefish/host/commands/cvd/cli:command_request",
7071
"//cuttlefish/host/commands/cvd/cli:types",
7172
"//cuttlefish/host/commands/cvd/cli/commands:command_handler",
@@ -161,6 +162,7 @@ cf_cc_library(
161162
srcs = ["fleet.cpp"],
162163
hdrs = ["fleet.h"],
163164
deps = [
165+
"//cuttlefish/common/libs/utils:flag_parser",
164166
"//cuttlefish/host/commands/cvd/cli:command_request",
165167
"//cuttlefish/host/commands/cvd/cli:types",
166168
"//cuttlefish/host/commands/cvd/cli/commands:command_handler",
@@ -281,6 +283,7 @@ cf_cc_library(
281283
srcs = ["power_btn.cpp"],
282284
hdrs = ["power_btn.h"],
283285
deps = [
286+
"//cuttlefish/common/libs/utils:flag_parser",
284287
"//cuttlefish/host/commands/cvd/cli:command_request",
285288
"//cuttlefish/host/commands/cvd/cli:types",
286289
"//cuttlefish/host/commands/cvd/cli/commands:command_handler",
@@ -316,6 +319,7 @@ cf_cc_library(
316319
srcs = ["remove.cpp"],
317320
hdrs = ["remove.h"],
318321
deps = [
322+
"//cuttlefish/common/libs/utils:flag_parser",
319323
"//cuttlefish/host/commands/cvd/cli:command_request",
320324
"//cuttlefish/host/commands/cvd/cli:types",
321325
"//cuttlefish/host/commands/cvd/cli:utils",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
#include <memory>
2020
#include <string>
21+
#include <vector>
2122

23+
#include "cuttlefish/common/libs/utils/flag_parser.h"
2224
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
2325
#include "cuttlefish/host/commands/cvd/cli/commands/command_handler.h"
2426
#include "cuttlefish/host/commands/cvd/cli/types.h"
@@ -53,6 +55,8 @@ CvdClearCommandHandler::CvdClearCommandHandler(
5355

5456
Result<void> CvdClearCommandHandler::Handle(const CommandRequest& request) {
5557
CF_EXPECT(CanHandle(request));
58+
std::vector<std::string> args = request.SubcommandArguments();
59+
CF_EXPECT(ConsumeFlags({UnexpectedArgumentGuard()}, args));
5660
CF_EXPECT(instance_manager_.Clear());
5761
return {};
5862
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <json/value.h>
2525

26+
#include "cuttlefish/common/libs/utils/flag_parser.h"
2627
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
2728
#include "cuttlefish/host/commands/cvd/cli/commands/command_handler.h"
2829
#include "cuttlefish/host/commands/cvd/cli/types.h"
@@ -69,8 +70,7 @@ Result<void> CvdFleetCommandHandler::Handle(const CommandRequest& request) {
6970
CF_EXPECT(CanHandle(request));
7071

7172
std::vector<std::string> args = request.SubcommandArguments();
72-
73-
73+
CF_EXPECT(ConsumeFlags({UnexpectedArgumentGuard()}, args));
7474

7575
auto all_groups = CF_EXPECT(instance_manager_.FindGroups({}));
7676
Json::Value groups_json(Json::arrayValue);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct LogsCmdOptions {
3737
return {
3838
GflagsCompatFlag("print", print_target)
3939
.Alias({FlagAliasMode::kFlagConsumesFollowing, "-p"}),
40+
UnexpectedArgumentGuard(),
4041
};
4142
}
4243
};

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include "cuttlefish/common/libs/fs/shared_buf.h"
4343
#include "cuttlefish/common/libs/fs/shared_fd.h"
44+
#include "cuttlefish/common/libs/utils/flag_parser.h"
4445
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
4546
#include "cuttlefish/host/commands/cvd/cli/commands/command_handler.h"
4647
#include "cuttlefish/host/commands/cvd/cli/selector/selector.h"
@@ -185,6 +186,9 @@ class CvdMonitorCommandHandler : public CvdCommandHandler {
185186
CF_EXPECT(isatty(0),
186187
"The monitor command requires an interactive terminal.");
187188

189+
std::vector<std::string> args = request.SubcommandArguments();
190+
CF_EXPECT(ConsumeFlags({UnexpectedArgumentGuard()}, args));
191+
188192
auto [instance, unused] =
189193
CF_EXPECT(selector::SelectInstance(instance_manager_, request),
190194
"Unable to select an instance");

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
#include <memory>
2020
#include <string>
21+
#include <vector>
2122

23+
#include "cuttlefish/common/libs/utils/flag_parser.h"
2224
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
2325
#include "cuttlefish/host/commands/cvd/cli/commands/command_handler.h"
2426
#include "cuttlefish/host/commands/cvd/cli/selector/selector.h"
@@ -40,6 +42,8 @@ class CvdDevicePowerBtnCommandHandler : public CvdCommandHandler {
4042

4143
Result<void> Handle(const CommandRequest& request) override {
4244
CF_EXPECT(CanHandle(request));
45+
std::vector<std::string> args = request.SubcommandArguments();
46+
CF_EXPECT(ConsumeFlags({UnexpectedArgumentGuard()}, args));
4347
auto [instance, _] =
4448
CF_EXPECT(selector::SelectInstance(instance_manager_, request),
4549
"Unable to select an instance");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct PowerwashOptions {
5555
return {
5656
GflagsCompatFlag("wait_for_launcher", wait_for_launcher_seconds),
5757
GflagsCompatFlag("boot_timeout", boot_timeout_seconds),
58+
UnexpectedArgumentGuard(),
5859
};
5960
}
6061
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "absl/log/log.h"
2525

26+
#include "cuttlefish/common/libs/utils/flag_parser.h"
2627
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
2728
#include "cuttlefish/host/commands/cvd/cli/commands/command_handler.h"
2829
#include "cuttlefish/host/commands/cvd/cli/selector/selector.h"
@@ -59,6 +60,7 @@ class RemoveCvdCommandHandler : public CvdCommandHandler {
5960
Result<void> Handle(const CommandRequest& request) override {
6061
CF_EXPECT(CanHandle(request));
6162
std::vector<std::string> subcmd_args = request.SubcommandArguments();
63+
CF_EXPECT(ConsumeFlags({UnexpectedArgumentGuard()}, subcmd_args));
6264

6365
if (!CF_EXPECT(instance_manager_.HasInstanceGroups())) {
6466
return CF_ERR(NoGroupMessage(request));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct RestartOptions {
5454
return {
5555
GflagsCompatFlag("wait_for_launcher", wait_for_launcher_seconds),
5656
GflagsCompatFlag("boot_timeout", boot_timeout_seconds),
57+
UnexpectedArgumentGuard(),
5758
};
5859
}
5960
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Result<StatusCommandOptions> ParseFlags(cvd_common::Args& args) {
104104
GflagsCompatFlag("wait_for_launcher", ret.wait_for_launcher_seconds),
105105
GflagsCompatFlag("instance_name", ret.instance_name),
106106
GflagsCompatFlag("print", ret.print),
107-
107+
UnexpectedArgumentGuard(),
108108
};
109109

110110
CF_EXPECT(ConsumeFlags(flags, args));

0 commit comments

Comments
 (0)