Merge changes I3fc0f159,I06068cbd,I76405e94,I255e2d94 into main
* changes: registerNix* -> registerLegacyNix* LegacyCommands -> LegacyCommandRegistry Commands -> CommandMap RegisterCommand::Commands -> CommandMap
This commit is contained in:
committed by
Lix Systems Gerrit
commit
ccab8cdd30
@@ -394,8 +394,8 @@ connected:
|
||||
}
|
||||
}
|
||||
|
||||
void registerBuildRemote() {
|
||||
LegacyCommands::add("build-remote", main_build_remote);
|
||||
void registerLegacyBuildRemote() {
|
||||
LegacyCommandRegistry::add("build-remote", main_build_remote);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerBuildRemote();
|
||||
void registerLegacyBuildRemote();
|
||||
|
||||
}
|
||||
|
||||
@@ -633,9 +633,9 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixBuildAndNixShell() {
|
||||
LegacyCommands::add("nix-build", main_nix_build);
|
||||
LegacyCommands::add("nix-shell", main_nix_build);
|
||||
void registerLegacyNixBuildAndNixShell() {
|
||||
LegacyCommandRegistry::add("nix-build", main_nix_build);
|
||||
LegacyCommandRegistry::add("nix-shell", main_nix_build);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixBuildAndNixShell();
|
||||
void registerLegacyNixBuildAndNixShell();
|
||||
|
||||
}
|
||||
|
||||
@@ -278,8 +278,8 @@ static int main_nix_channel(AsyncIoRoot & aio, std::string programName, Strings
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixChannel() {
|
||||
LegacyCommands::add("nix-channel", main_nix_channel);
|
||||
void registerLegacyNixChannel() {
|
||||
LegacyCommandRegistry::add("nix-channel", main_nix_channel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixChannel();
|
||||
void registerLegacyNixChannel();
|
||||
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ static int main_nix_collect_garbage(AsyncIoRoot & aio, std::string programName,
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixCollectGarbage() {
|
||||
LegacyCommands::add("nix-collect-garbage", main_nix_collect_garbage);
|
||||
void registerLegacyNixCollectGarbage() {
|
||||
LegacyCommandRegistry::add("nix-collect-garbage", main_nix_collect_garbage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixCollectGarbage();
|
||||
void registerLegacyNixCollectGarbage();
|
||||
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ static int main_nix_copy_closure(AsyncIoRoot & aio, std::string programName, Str
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixCopyClosure() {
|
||||
LegacyCommands::add("nix-copy-closure", main_nix_copy_closure);
|
||||
void registerLegacyNixCopyClosure() {
|
||||
LegacyCommandRegistry::add("nix-copy-closure", main_nix_copy_closure);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixCopyClosure();
|
||||
void registerLegacyNixCopyClosure();
|
||||
|
||||
}
|
||||
|
||||
@@ -1578,8 +1578,8 @@ static int main_nix_env(AsyncIoRoot & aio, std::string programName, Strings argv
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixEnv() {
|
||||
LegacyCommands::add("nix-env", main_nix_env);
|
||||
void registerLegacyNixEnv() {
|
||||
LegacyCommandRegistry::add("nix-env", main_nix_env);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixEnv();
|
||||
void registerLegacyNixEnv();
|
||||
|
||||
}
|
||||
|
||||
@@ -196,8 +196,8 @@ static int main_nix_instantiate(AsyncIoRoot & aio, std::string programName, Stri
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixInstantiate() {
|
||||
LegacyCommands::add("nix-instantiate", main_nix_instantiate);
|
||||
void registerLegacyNixInstantiate() {
|
||||
LegacyCommandRegistry::add("nix-instantiate", main_nix_instantiate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixInstantiate();
|
||||
void registerLegacyNixInstantiate();
|
||||
|
||||
}
|
||||
|
||||
@@ -1223,8 +1223,8 @@ static int main_nix_store(AsyncIoRoot & aio, std::string programName, Strings ar
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixStore() {
|
||||
LegacyCommands::add("nix-store", main_nix_store);
|
||||
void registerLegacyNixStore() {
|
||||
LegacyCommandRegistry::add("nix-store", main_nix_store);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixStore();
|
||||
void registerLegacyNixStore();
|
||||
|
||||
}
|
||||
|
||||
+12
-7
@@ -12,19 +12,24 @@ extern char * * environ __attribute__((weak));
|
||||
|
||||
namespace nix {
|
||||
|
||||
RegisterCommand::Commands * RegisterCommand::commands = nullptr;
|
||||
RegisterCommand::CommandMap * RegisterCommand::commands = nullptr;
|
||||
|
||||
nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
|
||||
nix::CommandMap RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
|
||||
{
|
||||
nix::Commands res;
|
||||
for (auto & [name, command] : *RegisterCommand::commands)
|
||||
nix::CommandMap res;
|
||||
for (auto & [name, command] : *RegisterCommand::commands) {
|
||||
if (name.size() == prefix.size() + 1) {
|
||||
bool equal = true;
|
||||
for (size_t i = 0; i < prefix.size(); ++i)
|
||||
if (name[i] != prefix[i]) equal = false;
|
||||
if (equal)
|
||||
for (size_t i = 0; i < prefix.size(); ++i) {
|
||||
if (name[i] != prefix[i]) {
|
||||
equal = false;
|
||||
}
|
||||
}
|
||||
if (equal) {
|
||||
res.insert_or_assign(name[prefix.size()], command);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -264,20 +264,20 @@ struct StorePathCommand : public StorePathsCommand
|
||||
*/
|
||||
struct RegisterCommand
|
||||
{
|
||||
typedef std::map<
|
||||
using CommandMap = std::map<
|
||||
std::vector<std::string>,
|
||||
std::function<ref<Command>(AsyncIoRoot & aio)>
|
||||
> Commands;
|
||||
static Commands * commands;
|
||||
>;
|
||||
static CommandMap * commands;
|
||||
|
||||
RegisterCommand(std::vector<std::string> && name,
|
||||
std::function<ref<Command>(AsyncIoRoot & aio)> command)
|
||||
{
|
||||
if (!commands) commands = new Commands;
|
||||
if (!commands) commands = new CommandMap;
|
||||
commands->emplace(name, command);
|
||||
}
|
||||
|
||||
static nix::Commands getCommandsFor(const std::vector<std::string> & prefix);
|
||||
static nix::CommandMap getCommandsFor(const std::vector<std::string> & prefix);
|
||||
};
|
||||
|
||||
template<typename Base>
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
LegacyCommands::Commands * LegacyCommands::commands = 0;
|
||||
LegacyCommandRegistry::LegacyCommandMap * LegacyCommandRegistry::commands = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ namespace nix {
|
||||
|
||||
typedef std::function<void(AsyncIoRoot &, std::string, std::list<std::string>)> MainFunction;
|
||||
|
||||
struct LegacyCommands
|
||||
struct LegacyCommandRegistry
|
||||
{
|
||||
typedef std::map<std::string, MainFunction> Commands;
|
||||
static Commands * commands;
|
||||
using LegacyCommandMap = std::map<std::string, MainFunction>;
|
||||
static LegacyCommandMap * commands;
|
||||
|
||||
static void add(const std::string & name, MainFunction fun)
|
||||
{
|
||||
if (!commands) commands = new Commands;
|
||||
if (!commands) commands = new LegacyCommandMap;
|
||||
(*commands)[name] = fun;
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -458,7 +458,7 @@ std::optional<ExperimentalFeature> Command::experimentalFeature ()
|
||||
return { Xp::NixCommand };
|
||||
}
|
||||
|
||||
MultiCommand::MultiCommand(const Commands & commands_, bool allowExternal)
|
||||
MultiCommand::MultiCommand(const CommandMap & commands_, bool allowExternal)
|
||||
: commands(commands_),
|
||||
customCommandSearchPaths(
|
||||
allowExternal ? tokenizeString<Strings>(
|
||||
|
||||
+3
-3
@@ -350,7 +350,7 @@ struct Command : virtual public Args
|
||||
virtual Category category() { return catDefault; }
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::function<ref<Command>(AsyncIoRoot &)>> Commands;
|
||||
using CommandMap = std::map<std::string, std::function<ref<Command>(AsyncIoRoot &)>>;
|
||||
|
||||
/**
|
||||
* An argument parser that supports multiple subcommands,
|
||||
@@ -359,7 +359,7 @@ typedef std::map<std::string, std::function<ref<Command>(AsyncIoRoot &)>> Comman
|
||||
class MultiCommand : public Command
|
||||
{
|
||||
public:
|
||||
Commands commands;
|
||||
CommandMap commands;
|
||||
Strings customCommandSearchPaths;
|
||||
bool isExternalSubcommand;
|
||||
|
||||
@@ -370,7 +370,7 @@ public:
|
||||
*/
|
||||
std::optional<std::pair<std::string, ref<Command>>> command;
|
||||
|
||||
MultiCommand(const Commands & commands, bool allowExternal = false);
|
||||
MultiCommand(const CommandMap & commands, bool allowExternal = false);
|
||||
|
||||
bool processFlag(Strings::iterator & pos, Strings::iterator end) override;
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixDaemon();
|
||||
void registerLegacyNixDaemon();
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -515,8 +515,8 @@ static int main_nix_daemon(AsyncIoRoot & aio, std::string programName, Strings a
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixDaemon() {
|
||||
LegacyCommands::add("nix-daemon", main_nix_daemon);
|
||||
void registerLegacyNixDaemon() {
|
||||
LegacyCommandRegistry::add("nix-daemon", main_nix_daemon);
|
||||
}
|
||||
|
||||
struct CmdDaemon : StoreCommand
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixHash();
|
||||
void registerLegacyNixHash();
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -233,8 +233,8 @@ static int compatNixHash(AsyncIoRoot & aio, std::string programName, Strings arg
|
||||
return 0;
|
||||
}
|
||||
|
||||
void registerNixHash() {
|
||||
LegacyCommands::add("nix-hash", compatNixHash);
|
||||
void registerLegacyNixHash() {
|
||||
LegacyCommandRegistry::add("nix-hash", compatNixHash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-12
@@ -43,17 +43,17 @@ namespace nix {
|
||||
|
||||
void registerLegacyCommands()
|
||||
{
|
||||
registerNixEnv();
|
||||
registerNixBuildAndNixShell();
|
||||
registerNixInstantiate();
|
||||
registerNixCopyClosure();
|
||||
registerNixCollectGarbage();
|
||||
registerNixChannel();
|
||||
registerNixStore();
|
||||
registerBuildRemote();
|
||||
registerNixDaemon();
|
||||
registerNixPrefetchUrl();
|
||||
registerNixHash();
|
||||
registerLegacyNixEnv();
|
||||
registerLegacyNixBuildAndNixShell();
|
||||
registerLegacyNixInstantiate();
|
||||
registerLegacyNixCopyClosure();
|
||||
registerLegacyNixCollectGarbage();
|
||||
registerLegacyNixChannel();
|
||||
registerLegacyNixStore();
|
||||
registerLegacyBuildRemote();
|
||||
registerLegacyNixDaemon();
|
||||
registerLegacyNixPrefetchUrl();
|
||||
registerLegacyNixHash();
|
||||
}
|
||||
|
||||
static bool haveProxyEnvironmentVariables()
|
||||
@@ -393,7 +393,7 @@ void mainWrapped(AsyncIoRoot & aio, int argc, char * * argv)
|
||||
|
||||
{
|
||||
registerLegacyCommands();
|
||||
auto legacy = (*LegacyCommands::commands)[programName];
|
||||
auto legacy = (*LegacyCommandRegistry::commands)[programName];
|
||||
if (legacy) {
|
||||
return legacy(aio, std::string(baseNameOf(argv[0])), Strings(argv + 1, argv + argc));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
void registerNixPrefetchUrl();
|
||||
void registerLegacyNixPrefetchUrl();
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -255,8 +255,8 @@ static int main_nix_prefetch_url(AsyncIoRoot & aio, std::string programName, Str
|
||||
}
|
||||
}
|
||||
|
||||
void registerNixPrefetchUrl() {
|
||||
LegacyCommands::add("nix-prefetch-url", main_nix_prefetch_url);
|
||||
void registerLegacyNixPrefetchUrl() {
|
||||
LegacyCommandRegistry::add("nix-prefetch-url", main_nix_prefetch_url);
|
||||
}
|
||||
|
||||
struct CmdStorePrefetchFile : StoreCommand, MixJSON
|
||||
|
||||
Reference in New Issue
Block a user