diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-06-18 16:01:35 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-12-05 20:19:26 +0100 |
commit | ac676856061677559a21670940ac2fac98add9a0 (patch) | |
tree | 0f5444034c6262f8ad92f0fd10c8dcf2b95a8e0c /src/nix/command.hh | |
parent | f964f428fe6975e06a273e43c3266928a407454f (diff) |
Make subcommand construction in MultiCommand lazy
(cherry picked from commit a0de58f471c9087d8e6cc60a6078f9940a125b15)
Diffstat (limited to 'src/nix/command.hh')
-rw-r--r-- | src/nix/command.hh | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/nix/command.hh b/src/nix/command.hh index aa34301d9..7474c5eae 100644 --- a/src/nix/command.hh +++ b/src/nix/command.hh @@ -151,15 +151,22 @@ struct StorePathCommand : public InstallablesCommand /* A helper class for registering commands globally. */ struct RegisterCommand { - static std::vector<ref<Command>> * commands; + static Commands * commands; - RegisterCommand(ref<Command> command) + RegisterCommand(const std::string & name, + std::function<ref<Command>()> command) { - if (!commands) commands = new std::vector<ref<Command>>; - commands->push_back(command); + if (!commands) commands = new Commands; + commands->emplace(name, command); } }; +template<class T> +static RegisterCommand registerCommand(const std::string & name) +{ + return RegisterCommand(name, [](){ return make_ref<T>(); }); +} + std::shared_ptr<Installable> parseInstallable( SourceExprCommand & cmd, ref<Store> store, const std::string & installable, bool useDefaultInstallables); |