diff --git a/lix/libcmd/command.cc b/lix/libcmd/command.cc index 907734821..54502fd56 100644 --- a/lix/libcmd/command.cc +++ b/lix/libcmd/command.cc @@ -12,19 +12,24 @@ extern char * * environ __attribute__((weak)); namespace nix { -RegisterCommand::Commands * RegisterCommand::commands = nullptr; +RegisterCommand::CommandMap * RegisterCommand::commands = nullptr; nix::Commands RegisterCommand::getCommandsFor(const std::vector & prefix) { nix::Commands res; - for (auto & [name, command] : *RegisterCommand::commands) + for (auto & [name, command] : *RegisterCommand::commands) { if (name.size() == prefix.size() + 1) { bool equal = true; - for (size_t i = 0; i < prefix.size(); ++i) - if (name[i] != prefix[i]) equal = false; - if (equal) + for (size_t i = 0; i < prefix.size(); ++i) { + if (name[i] != prefix[i]) { + equal = false; + } + } + if (equal) { res.insert_or_assign(name[prefix.size()], command); + } } + } return res; } diff --git a/lix/libcmd/command.hh b/lix/libcmd/command.hh index 82ad562e5..c6fe424ff 100644 --- a/lix/libcmd/command.hh +++ b/lix/libcmd/command.hh @@ -264,16 +264,16 @@ struct StorePathCommand : public StorePathsCommand */ struct RegisterCommand { - typedef std::map< + using CommandMap = std::map< std::vector, std::function(AsyncIoRoot & aio)> - > Commands; - static Commands * commands; + >; + static CommandMap * commands; RegisterCommand(std::vector && name, std::function(AsyncIoRoot & aio)> command) { - if (!commands) commands = new Commands; + if (!commands) commands = new CommandMap; commands->emplace(name, command); } diff --git a/lix/libcmd/legacy.cc b/lix/libcmd/legacy.cc index 05ac2dcd4..4946d712b 100644 --- a/lix/libcmd/legacy.cc +++ b/lix/libcmd/legacy.cc @@ -2,6 +2,6 @@ namespace nix { -LegacyCommands::Commands * LegacyCommands::commands = 0; +LegacyCommands::LegacyCommandMap * LegacyCommands::commands = 0; } diff --git a/lix/libcmd/legacy.hh b/lix/libcmd/legacy.hh index ab1f1881d..b412b42dc 100644 --- a/lix/libcmd/legacy.hh +++ b/lix/libcmd/legacy.hh @@ -13,12 +13,12 @@ typedef std::function)> struct LegacyCommands { - typedef std::map Commands; - static Commands * commands; + using LegacyCommandMap = std::map; + static LegacyCommandMap * commands; static void add(const std::string & name, MainFunction fun) { - if (!commands) commands = new Commands; + if (!commands) commands = new LegacyCommandMap; (*commands)[name] = fun; } };