mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
Simplify RegisterCommand
This commit is contained in:
parent
4de7a986d4
commit
e7c0906521
2 changed files with 8 additions and 7 deletions
|
@ -14,12 +14,10 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
RegisterCommand::Commands * RegisterCommand::commands = nullptr;
|
||||
|
||||
nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & 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)
|
||||
|
|
|
@ -285,13 +285,16 @@ struct StorePathCommand : public StorePathsCommand
|
|||
struct RegisterCommand
|
||||
{
|
||||
typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands;
|
||||
static Commands * commands;
|
||||
|
||||
static Commands & commands()
|
||||
{
|
||||
static Commands commands;
|
||||
return commands;
|
||||
}
|
||||
|
||||
RegisterCommand(std::vector<std::string> && name, std::function<ref<Command>()> command)
|
||||
{
|
||||
if (!commands)
|
||||
commands = new Commands;
|
||||
commands->emplace(name, command);
|
||||
commands().emplace(name, command);
|
||||
}
|
||||
|
||||
static nix::Commands getCommandsFor(const std::vector<std::string> & prefix);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue