1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

Simplify RegisterLegacyCommand

This commit is contained in:
Eelco Dolstra 2025-05-05 08:22:53 +02:00
parent bd80a4f176
commit b7add9736c
4 changed files with 7 additions and 12 deletions

View file

@ -12,12 +12,15 @@ typedef std::function<void(int, char * *)> MainFunction;
struct RegisterLegacyCommand
{
typedef std::map<std::string, MainFunction> Commands;
static Commands * commands;
static Commands & commands() {
static Commands commands;
return commands;
}
RegisterLegacyCommand(const std::string & name, MainFunction fun)
{
if (!commands) commands = new Commands;
(*commands)[name] = fun;
commands()[name] = fun;
}
};

View file

@ -1,7 +0,0 @@
#include "nix/cmd/legacy.hh"
namespace nix {
RegisterLegacyCommand::Commands * RegisterLegacyCommand::commands = 0;
}

View file

@ -71,7 +71,6 @@ sources = files(
'installable-flake.cc',
'installable-value.cc',
'installables.cc',
'legacy.cc',
'markdown.cc',
'misc-store-flags.cc',
'network-proxy.cc',

View file

@ -373,7 +373,7 @@ void mainWrapped(int argc, char * * argv)
}
{
auto legacy = (*RegisterLegacyCommand::commands)[programName];
auto legacy = RegisterLegacyCommand::commands()[programName];
if (legacy) return legacy(argc, argv);
}