diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-04-16 00:34:58 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-16 00:34:58 +0000 |
commit | 2352e5e7f6db32ae6a73cc5a3df35ea97ec5fea4 (patch) | |
tree | 0842b444117d096a66ab33e21774cc2d916a6687 | |
parent | e17192e414382a3675bafb3a3e298f7bf1575092 (diff) | |
parent | 63b903e431f0fcf372efab693651ea7a5b66575f (diff) | |
download | cuttlefish-2352e5e7f6db32ae6a73cc5a3df35ea97ec5fea4.tar.gz |
Merge "Remove static initializers in cvd_internal_display" into main
-rw-r--r-- | host/commands/display/main.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/host/commands/display/main.cpp b/host/commands/display/main.cpp index 7e02dc662..990bd3ea2 100644 --- a/host/commands/display/main.cpp +++ b/host/commands/display/main.cpp @@ -21,6 +21,7 @@ #include <vector> #include <android-base/logging.h> +#include <android-base/no_destructor.h> #include <android-base/strings.h> #include "common/libs/utils/flag_parser.h" @@ -32,7 +33,7 @@ namespace cuttlefish { namespace { -static const std::string kAddUsage = +static const char kAddUsage[] = R"( Adds and connects a display to the given virtual device. @@ -42,7 +43,7 @@ usage: cvd display add \\ --display=width=1920,height=1080,refresh_rate_hz=60 )"; -static const std::string kListUsage = +static const char kListUsage[] = R"( Lists all of the displays currently connected to a given virtual device. @@ -50,7 +51,7 @@ Lists all of the displays currently connected to a given virtual device. usage: cvd display list )"; -static const std::string kRemoveUsage = +static const char kRemoveUsage[] = R"( Disconnects and removes displays from the given virtual device. @@ -60,12 +61,6 @@ usage: cvd display remove \\ --display=<display id> ... )"; -static const std::unordered_map<std::string, std::string> kSubCommandUsages = { - {"add", kAddUsage}, - {"list", kListUsage}, - {"remove", kRemoveUsage}, -}; - Result<int> RunCrosvmDisplayCommand(int instance_num, const std::vector<std::string>& args) { auto config = cuttlefish::CuttlefishConfig::Get(); @@ -109,9 +104,17 @@ Result<int> GetInstanceNum(std::vector<std::string>& args) { } Result<int> DoHelp(std::vector<std::string>& args) { + static const android::base::NoDestructor< + std::unordered_map<std::string, std::string>> + kSubCommandUsages({ + {"add", kAddUsage}, + {"list", kListUsage}, + {"remove", kRemoveUsage}, + }); + const std::string& subcommand_str = args[0]; - auto subcommand_usage = kSubCommandUsages.find(subcommand_str); - if (subcommand_usage == kSubCommandUsages.end()) { + auto subcommand_usage = kSubCommandUsages->find(subcommand_str); + if (subcommand_usage == kSubCommandUsages->end()) { std::cerr << "Unknown subcommand '" << subcommand_str << "'. See `cvd display help`" << std::endl; return 1; |