1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
///@file

#include "lix/libutil/async.hh"
#include <functional>
#include <list>
#include <map>
#include <span>
#include <string>

namespace nix {

struct LegacyCommandRegistry
{
    typedef std::function<int(AsyncIoRoot &, std::string, std::list<std::string>)> MainFunction;
    typedef std::function<
        int(AsyncIoRoot &, std::string, std::list<std::string>, std::span<char *>)>
        RawMainFunction;

    using LegacyCommandMap = std::map<std::string, RawMainFunction>;
    static LegacyCommandMap * commands;

    static void add(const std::string & name, MainFunction fun)
    {
        addWithRaw(
            name,
            [fun](AsyncIoRoot & aio, std::string name, std::list<std::string> args, std::span<char *>) {
                return fun(aio, name, args);
            }
        );
    }

    static void addWithRaw(const std::string & name, RawMainFunction fun)
    {
        if (!commands) commands = new LegacyCommandMap;
        (*commands)[name] = fun;
    }
};

}