lshal: Add class Command.
Command is the base class for all *Command classes.
Test: lshal_test
Bug: 35389839
Change-Id: I9aca19e66824536d13e618ffd0f012ac3da9880d
diff --git a/cmds/lshal/Lshal.cpp b/cmds/lshal/Lshal.cpp
index da45d65..9c5c234 100644
--- a/cmds/lshal/Lshal.cpp
+++ b/cmds/lshal/Lshal.cpp
@@ -218,6 +218,17 @@
}
}
+std::unique_ptr<Command> Lshal::selectCommand(const std::string& command) {
+ // Default command is list
+ if (command == "list" || command == "") {
+ return std::make_unique<ListCommand>(*this);
+ }
+ if (command == "debug") {
+ return std::make_unique<DebugCommand>(*this);
+ }
+ return nullptr;
+}
+
Status Lshal::main(const Arg &arg) {
// Allow SIGINT to terminate all threads.
signal(SIGINT, signalHandler);
@@ -230,12 +241,9 @@
usage(optind < arg.argc ? arg.argv[optind] : "");
return USAGE;
}
- // Default command is list
- if (mCommand == "list" || mCommand == "") {
- return ListCommand{*this}.main(mCommand, arg);
- }
- if (mCommand == "debug") {
- return DebugCommand{*this}.main(mCommand, arg);
+ auto c = selectCommand(mCommand);
+ if (c != nullptr) {
+ return c->main(mCommand, arg);
}
usage();
return USAGE;