Skip to content

Commit bdc516c

Browse files
committed
cvd: Cleanup unused CommandSequenceExecutor code
Remove unused methods, variables, and simplify function signatures: - Remove unused CmdList() from CommandSequenceExecutor. - Remove unused handler_stack_ from CommandSequenceExecutor. - Remove unused std::ostream report parameter from ExecuteOne, logging to std::cerr directly. Assisted-by: Jetski
1 parent ee799d9 commit bdc516c

4 files changed

Lines changed: 9 additions & 25 deletions

File tree

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
#include "cuttlefish/host/commands/cvd/cli/command_sequence.h"
1717

18+
#include <iostream>
1819
#include <memory>
1920
#include <ostream>
2021
#include <sstream>
2122
#include <string>
22-
#include <unordered_set>
2323
#include <vector>
2424

2525
#include "absl/strings/str_replace.h"
@@ -80,29 +80,15 @@ CommandSequenceExecutor::CommandSequenceExecutor(
8080
const std::vector<std::unique_ptr<CvdCommandHandler>>& server_handlers)
8181
: server_handlers_(server_handlers) {}
8282

83-
Result<void> CommandSequenceExecutor::ExecuteOne(const CommandRequest& request,
84-
std::ostream& report) {
85-
report << FormattedCommand(request);
83+
Result<void> CommandSequenceExecutor::ExecuteOne(
84+
const CommandRequest& request) {
85+
std::cerr << FormattedCommand(request);
8686

8787
auto handler = CF_EXPECT(RequestHandler(request, server_handlers_));
88-
handler_stack_.push_back(handler);
8988
CF_EXPECT(handler->Handle(request));
90-
handler_stack_.pop_back();
9189
return {};
9290
}
9391

94-
std::vector<std::string> CommandSequenceExecutor::CmdList() const {
95-
std::unordered_set<std::string> subcmds;
96-
for (const auto& handler : server_handlers_) {
97-
auto&& cmds_list = handler->CmdList();
98-
for (const auto& cmd : cmds_list) {
99-
subcmds.insert(cmd);
100-
}
101-
}
102-
// duplication removed
103-
return std::vector<std::string>{subcmds.begin(), subcmds.end()};
104-
}
105-
10692
Result<CvdCommandHandler*> CommandSequenceExecutor::GetHandler(
10793
const CommandRequest& request) {
10894
return CF_EXPECT(RequestHandler(request, server_handlers_));

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ class CommandSequenceExecutor {
3030
CommandSequenceExecutor(
3131
const std::vector<std::unique_ptr<CvdCommandHandler>>& server_handlers);
3232

33-
Result<void> ExecuteOne(const CommandRequest&, std::ostream& report);
33+
Result<void> ExecuteOne(const CommandRequest&);
3434

35-
std::vector<std::string> CmdList() const;
3635
Result<CvdCommandHandler*> GetHandler(const CommandRequest& request);
3736

3837
private:
3938
const std::vector<std::unique_ptr<CvdCommandHandler>>& server_handlers_;
40-
std::vector<CvdCommandHandler*> handler_stack_;
4139
};
4240
} // namespace cuttlefish

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ Result<void> CvdCreateCommandHandler::Handle(const CommandRequest& request) {
304304
if (!flags.config_file.empty()) {
305305
auto subrequest =
306306
CF_EXPECT(CreateLoadCommand(request, subcmd_args, flags.config_file));
307-
CF_EXPECT(command_executor_.ExecuteOne(subrequest, std::cerr));
307+
CF_EXPECT(command_executor_.ExecuteOne(subrequest));
308308
return {};
309309
}
310310

@@ -329,7 +329,7 @@ Result<void> CvdCreateCommandHandler::Handle(const CommandRequest& request) {
329329

330330
if (flags.start) {
331331
auto start_cmd = CF_EXPECT(CreateStartCommand(group, subcmd_args, envs));
332-
CF_EXPECT(command_executor_.ExecuteOne(start_cmd, std::cerr));
332+
CF_EXPECT(command_executor_.ExecuteOne(start_cmd));
333333

334334
if (CF_EXPECT(IsDefaultGroup(request))) {
335335
// For backward compatibility, we add extra symlink in system wide home

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class LoadConfigsCommand : public CvdCommandHandler {
167167

168168
if (!cvd_flags.fetch_cvd_flags.empty()) {
169169
auto fetch_cmd = CF_EXPECT(BuildFetchCmd(request, cvd_flags));
170-
auto fetch_res = executor_.ExecuteOne(fetch_cmd, std::cerr);
170+
auto fetch_res = executor_.ExecuteOne(fetch_cmd);
171171
if (!fetch_res.ok()) {
172172
group.SetAllStates(cvd::INSTANCE_STATE_PREPARE_FAILED);
173173
// TODO: b/471069557 - diagnose unused
@@ -183,7 +183,7 @@ class LoadConfigsCommand : public CvdCommandHandler {
183183
CF_EXPECT(instance_manager_.UpdateInstanceGroup(group));
184184

185185
auto start_cmd = CF_EXPECT(BuildStartCommand(request, cvd_flags, group));
186-
CF_EXPECT(executor_.ExecuteOne(start_cmd, std::cerr));
186+
CF_EXPECT(executor_.ExecuteOne(start_cmd));
187187
return {};
188188
}
189189

0 commit comments

Comments
 (0)