mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Simplify RegisterLegacyCommand
This commit is contained in:
parent
bd80a4f176
commit
b7add9736c
4 changed files with 7 additions and 12 deletions
|
@ -12,12 +12,15 @@ typedef std::function<void(int, char * *)> MainFunction;
|
||||||
struct RegisterLegacyCommand
|
struct RegisterLegacyCommand
|
||||||
{
|
{
|
||||||
typedef std::map<std::string, MainFunction> Commands;
|
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)
|
RegisterLegacyCommand(const std::string & name, MainFunction fun)
|
||||||
{
|
{
|
||||||
if (!commands) commands = new Commands;
|
commands()[name] = fun;
|
||||||
(*commands)[name] = fun;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#include "nix/cmd/legacy.hh"
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
RegisterLegacyCommand::Commands * RegisterLegacyCommand::commands = 0;
|
|
||||||
|
|
||||||
}
|
|
|
@ -71,7 +71,6 @@ sources = files(
|
||||||
'installable-flake.cc',
|
'installable-flake.cc',
|
||||||
'installable-value.cc',
|
'installable-value.cc',
|
||||||
'installables.cc',
|
'installables.cc',
|
||||||
'legacy.cc',
|
|
||||||
'markdown.cc',
|
'markdown.cc',
|
||||||
'misc-store-flags.cc',
|
'misc-store-flags.cc',
|
||||||
'network-proxy.cc',
|
'network-proxy.cc',
|
||||||
|
|
|
@ -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);
|
if (legacy) return legacy(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue