diff --git a/lix/legacy/build-remote.cc b/lix/legacy/build-remote.cc index 85ff12976..ea48e2423 100644 --- a/lix/legacy/build-remote.cc +++ b/lix/legacy/build-remote.cc @@ -394,8 +394,8 @@ connected: } } -void registerBuildRemote() { - LegacyCommands::add("build-remote", main_build_remote); +void registerLegacyBuildRemote() { + LegacyCommandRegistry::add("build-remote", main_build_remote); } } diff --git a/lix/legacy/build-remote.hh b/lix/legacy/build-remote.hh index c4a35f706..b9296c178 100644 --- a/lix/legacy/build-remote.hh +++ b/lix/legacy/build-remote.hh @@ -3,6 +3,6 @@ namespace nix { -void registerBuildRemote(); +void registerLegacyBuildRemote(); } diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index 6bc6b1870..ebaf4f37e 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -633,9 +633,9 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a } } -void registerNixBuildAndNixShell() { - LegacyCommands::add("nix-build", main_nix_build); - LegacyCommands::add("nix-shell", main_nix_build); +void registerLegacyNixBuildAndNixShell() { + LegacyCommandRegistry::add("nix-build", main_nix_build); + LegacyCommandRegistry::add("nix-shell", main_nix_build); } } diff --git a/lix/legacy/nix-build.hh b/lix/legacy/nix-build.hh index 945ac06e2..d18bca616 100644 --- a/lix/legacy/nix-build.hh +++ b/lix/legacy/nix-build.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixBuildAndNixShell(); +void registerLegacyNixBuildAndNixShell(); } diff --git a/lix/legacy/nix-channel.cc b/lix/legacy/nix-channel.cc index c994e8583..0343dd7bd 100644 --- a/lix/legacy/nix-channel.cc +++ b/lix/legacy/nix-channel.cc @@ -278,8 +278,8 @@ static int main_nix_channel(AsyncIoRoot & aio, std::string programName, Strings } } -void registerNixChannel() { - LegacyCommands::add("nix-channel", main_nix_channel); +void registerLegacyNixChannel() { + LegacyCommandRegistry::add("nix-channel", main_nix_channel); } } diff --git a/lix/legacy/nix-channel.hh b/lix/legacy/nix-channel.hh index f1583767f..1e0fc3f71 100644 --- a/lix/legacy/nix-channel.hh +++ b/lix/legacy/nix-channel.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixChannel(); +void registerLegacyNixChannel(); } diff --git a/lix/legacy/nix-collect-garbage.cc b/lix/legacy/nix-collect-garbage.cc index 6ea7b7240..3d736e6cd 100644 --- a/lix/legacy/nix-collect-garbage.cc +++ b/lix/legacy/nix-collect-garbage.cc @@ -112,8 +112,8 @@ static int main_nix_collect_garbage(AsyncIoRoot & aio, std::string programName, } } -void registerNixCollectGarbage() { - LegacyCommands::add("nix-collect-garbage", main_nix_collect_garbage); +void registerLegacyNixCollectGarbage() { + LegacyCommandRegistry::add("nix-collect-garbage", main_nix_collect_garbage); } } diff --git a/lix/legacy/nix-collect-garbage.hh b/lix/legacy/nix-collect-garbage.hh index 68515b537..ec542c3f2 100644 --- a/lix/legacy/nix-collect-garbage.hh +++ b/lix/legacy/nix-collect-garbage.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixCollectGarbage(); +void registerLegacyNixCollectGarbage(); } diff --git a/lix/legacy/nix-copy-closure.cc b/lix/legacy/nix-copy-closure.cc index 811485cd7..4f51b216a 100644 --- a/lix/legacy/nix-copy-closure.cc +++ b/lix/legacy/nix-copy-closure.cc @@ -61,8 +61,8 @@ static int main_nix_copy_closure(AsyncIoRoot & aio, std::string programName, Str } } -void registerNixCopyClosure() { - LegacyCommands::add("nix-copy-closure", main_nix_copy_closure); +void registerLegacyNixCopyClosure() { + LegacyCommandRegistry::add("nix-copy-closure", main_nix_copy_closure); } } diff --git a/lix/legacy/nix-copy-closure.hh b/lix/legacy/nix-copy-closure.hh index fb5d0fc6e..b5c0b6acb 100644 --- a/lix/legacy/nix-copy-closure.hh +++ b/lix/legacy/nix-copy-closure.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixCopyClosure(); +void registerLegacyNixCopyClosure(); } diff --git a/lix/legacy/nix-env.cc b/lix/legacy/nix-env.cc index 74fb44fbf..fdfd6194b 100644 --- a/lix/legacy/nix-env.cc +++ b/lix/legacy/nix-env.cc @@ -1578,8 +1578,8 @@ static int main_nix_env(AsyncIoRoot & aio, std::string programName, Strings argv } } -void registerNixEnv() { - LegacyCommands::add("nix-env", main_nix_env); +void registerLegacyNixEnv() { + LegacyCommandRegistry::add("nix-env", main_nix_env); } } diff --git a/lix/legacy/nix-env.hh b/lix/legacy/nix-env.hh index 47d62b8e6..6b0cc32df 100644 --- a/lix/legacy/nix-env.hh +++ b/lix/legacy/nix-env.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixEnv(); +void registerLegacyNixEnv(); } diff --git a/lix/legacy/nix-instantiate.cc b/lix/legacy/nix-instantiate.cc index f8db06ef9..90c485bdf 100644 --- a/lix/legacy/nix-instantiate.cc +++ b/lix/legacy/nix-instantiate.cc @@ -196,8 +196,8 @@ static int main_nix_instantiate(AsyncIoRoot & aio, std::string programName, Stri } } -void registerNixInstantiate() { - LegacyCommands::add("nix-instantiate", main_nix_instantiate); +void registerLegacyNixInstantiate() { + LegacyCommandRegistry::add("nix-instantiate", main_nix_instantiate); } } diff --git a/lix/legacy/nix-instantiate.hh b/lix/legacy/nix-instantiate.hh index f4c35a6b5..983dccbf2 100644 --- a/lix/legacy/nix-instantiate.hh +++ b/lix/legacy/nix-instantiate.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixInstantiate(); +void registerLegacyNixInstantiate(); } diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index 7eab7c69a..ed54fe36c 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -1223,8 +1223,8 @@ static int main_nix_store(AsyncIoRoot & aio, std::string programName, Strings ar } } -void registerNixStore() { - LegacyCommands::add("nix-store", main_nix_store); +void registerLegacyNixStore() { + LegacyCommandRegistry::add("nix-store", main_nix_store); } } diff --git a/lix/legacy/nix-store.hh b/lix/legacy/nix-store.hh index b010e7b19..a43fdebc8 100644 --- a/lix/legacy/nix-store.hh +++ b/lix/legacy/nix-store.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixStore(); +void registerLegacyNixStore(); } diff --git a/lix/libcmd/command.cc b/lix/libcmd/command.cc index 907734821..fb3daedcf 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::CommandMap RegisterCommand::getCommandsFor(const std::vector & prefix) { - nix::Commands res; - for (auto & [name, command] : *RegisterCommand::commands) + nix::CommandMap res; + 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..e6c910915 100644 --- a/lix/libcmd/command.hh +++ b/lix/libcmd/command.hh @@ -264,20 +264,20 @@ 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); } - static nix::Commands getCommandsFor(const std::vector & prefix); + static nix::CommandMap getCommandsFor(const std::vector & prefix); }; template diff --git a/lix/libcmd/legacy.cc b/lix/libcmd/legacy.cc index 05ac2dcd4..2c355f2e4 100644 --- a/lix/libcmd/legacy.cc +++ b/lix/libcmd/legacy.cc @@ -2,6 +2,6 @@ namespace nix { -LegacyCommands::Commands * LegacyCommands::commands = 0; +LegacyCommandRegistry::LegacyCommandMap * LegacyCommandRegistry::commands = 0; } diff --git a/lix/libcmd/legacy.hh b/lix/libcmd/legacy.hh index ab1f1881d..068fb9eb9 100644 --- a/lix/libcmd/legacy.hh +++ b/lix/libcmd/legacy.hh @@ -11,14 +11,14 @@ namespace nix { typedef std::function)> MainFunction; -struct LegacyCommands +struct LegacyCommandRegistry { - 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; } }; diff --git a/lix/libutil/args.cc b/lix/libutil/args.cc index 67d91c09c..de98c4fcc 100644 --- a/lix/libutil/args.cc +++ b/lix/libutil/args.cc @@ -458,7 +458,7 @@ std::optional Command::experimentalFeature () return { Xp::NixCommand }; } -MultiCommand::MultiCommand(const Commands & commands_, bool allowExternal) +MultiCommand::MultiCommand(const CommandMap & commands_, bool allowExternal) : commands(commands_), customCommandSearchPaths( allowExternal ? tokenizeString( diff --git a/lix/libutil/args.hh b/lix/libutil/args.hh index 8a5026547..9c911a9df 100644 --- a/lix/libutil/args.hh +++ b/lix/libutil/args.hh @@ -350,7 +350,7 @@ struct Command : virtual public Args virtual Category category() { return catDefault; } }; -typedef std::map(AsyncIoRoot &)>> Commands; +using CommandMap = std::map(AsyncIoRoot &)>>; /** * An argument parser that supports multiple subcommands, @@ -359,7 +359,7 @@ typedef std::map(AsyncIoRoot &)>> Comman class MultiCommand : public Command { public: - Commands commands; + CommandMap commands; Strings customCommandSearchPaths; bool isExternalSubcommand; @@ -370,7 +370,7 @@ public: */ std::optional>> command; - MultiCommand(const Commands & commands, bool allowExternal = false); + MultiCommand(const CommandMap & commands, bool allowExternal = false); bool processFlag(Strings::iterator & pos, Strings::iterator end) override; diff --git a/lix/nix/daemon-command.hh b/lix/nix/daemon-command.hh index 454af88e2..6cce1298c 100644 --- a/lix/nix/daemon-command.hh +++ b/lix/nix/daemon-command.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixDaemon(); +void registerLegacyNixDaemon(); } diff --git a/lix/nix/daemon.cc b/lix/nix/daemon.cc index 2caf5ee58..b401c68cd 100644 --- a/lix/nix/daemon.cc +++ b/lix/nix/daemon.cc @@ -515,8 +515,8 @@ static int main_nix_daemon(AsyncIoRoot & aio, std::string programName, Strings a } } -void registerNixDaemon() { - LegacyCommands::add("nix-daemon", main_nix_daemon); +void registerLegacyNixDaemon() { + LegacyCommandRegistry::add("nix-daemon", main_nix_daemon); } struct CmdDaemon : StoreCommand diff --git a/lix/nix/hash-command.hh b/lix/nix/hash-command.hh index 5383171a5..2e1a8050f 100644 --- a/lix/nix/hash-command.hh +++ b/lix/nix/hash-command.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixHash(); +void registerLegacyNixHash(); } diff --git a/lix/nix/hash.cc b/lix/nix/hash.cc index 2f3c40a39..c5cde872e 100644 --- a/lix/nix/hash.cc +++ b/lix/nix/hash.cc @@ -233,8 +233,8 @@ static int compatNixHash(AsyncIoRoot & aio, std::string programName, Strings arg return 0; } -void registerNixHash() { - LegacyCommands::add("nix-hash", compatNixHash); +void registerLegacyNixHash() { + LegacyCommandRegistry::add("nix-hash", compatNixHash); } } diff --git a/lix/nix/main.cc b/lix/nix/main.cc index fa1735906..9fb620abb 100644 --- a/lix/nix/main.cc +++ b/lix/nix/main.cc @@ -43,17 +43,17 @@ namespace nix { void registerLegacyCommands() { - registerNixEnv(); - registerNixBuildAndNixShell(); - registerNixInstantiate(); - registerNixCopyClosure(); - registerNixCollectGarbage(); - registerNixChannel(); - registerNixStore(); - registerBuildRemote(); - registerNixDaemon(); - registerNixPrefetchUrl(); - registerNixHash(); + registerLegacyNixEnv(); + registerLegacyNixBuildAndNixShell(); + registerLegacyNixInstantiate(); + registerLegacyNixCopyClosure(); + registerLegacyNixCollectGarbage(); + registerLegacyNixChannel(); + registerLegacyNixStore(); + registerLegacyBuildRemote(); + registerLegacyNixDaemon(); + registerLegacyNixPrefetchUrl(); + registerLegacyNixHash(); } static bool haveProxyEnvironmentVariables() @@ -393,7 +393,7 @@ void mainWrapped(AsyncIoRoot & aio, int argc, char * * argv) { registerLegacyCommands(); - auto legacy = (*LegacyCommands::commands)[programName]; + auto legacy = (*LegacyCommandRegistry::commands)[programName]; if (legacy) { return legacy(aio, std::string(baseNameOf(argv[0])), Strings(argv + 1, argv + argc)); } diff --git a/lix/nix/prefetch-command.hh b/lix/nix/prefetch-command.hh index 078e83485..7a5e54de1 100644 --- a/lix/nix/prefetch-command.hh +++ b/lix/nix/prefetch-command.hh @@ -3,6 +3,6 @@ namespace nix { -void registerNixPrefetchUrl(); +void registerLegacyNixPrefetchUrl(); } diff --git a/lix/nix/prefetch.cc b/lix/nix/prefetch.cc index 9d23c1d67..3f7bae7f8 100644 --- a/lix/nix/prefetch.cc +++ b/lix/nix/prefetch.cc @@ -255,8 +255,8 @@ static int main_nix_prefetch_url(AsyncIoRoot & aio, std::string programName, Str } } -void registerNixPrefetchUrl() { - LegacyCommands::add("nix-prefetch-url", main_nix_prefetch_url); +void registerLegacyNixPrefetchUrl() { + LegacyCommandRegistry::add("nix-prefetch-url", main_nix_prefetch_url); } struct CmdStorePrefetchFile : StoreCommand, MixJSON