lix/src/libcmd/legacy.hh
Rebecca Turner b63d4a0c62
Remove static initializers for RegisterLegacyCommand
This moves the "legacy"/"nix2" commands under a new `src/legacy/`
directory, instead of being scattered around in a bunch of different
directories.

A new `liblegacy` build target is defined, and the `nix` binary is
linked against it.

Then, `RegisterLegacyCommand` is replaced with `LegacyCommand::add`
calls in functions like `registerNixCollectGarbage()`. These
registration functions are called explicitly in `src/nix/main.cc`.

See: lix-project/lix#359

Change-Id: Id450ffc3f793374907599cfcc121863b792aac1a
2024-10-01 16:08:58 -07:00

25 lines
432 B
C++

#pragma once
///@file
#include <functional>
#include <map>
#include <string>
namespace nix {
typedef std::function<void(int, char * *)> MainFunction;
struct LegacyCommands
{
typedef std::map<std::string, MainFunction> Commands;
static Commands * commands;
static void add(const std::string & name, MainFunction fun)
{
if (!commands) commands = new Commands;
(*commands)[name] = fun;
}
};
}