aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/command.cc8
-rw-r--r--src/nix/command.hh8
-rw-r--r--src/nix/main.cc7
3 files changed, 15 insertions, 8 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index 724f03e5d..a40a113db 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -5,7 +5,7 @@
namespace nix {
-Commands * RegisterCommand::commands = 0;
+std::vector<ref<Command>> * RegisterCommand::commands = 0;
void Command::printHelp(const string & programName, std::ostream & out)
{
@@ -22,9 +22,11 @@ void Command::printHelp(const string & programName, std::ostream & out)
}
}
-MultiCommand::MultiCommand(const Commands & _commands)
- : commands(_commands)
+MultiCommand::MultiCommand(const std::vector<ref<Command>> & _commands)
{
+ for (auto & command : _commands)
+ commands.emplace(command->name(), command);
+
expectedArgs.push_back(ExpectedArg{"command", 1, true, [=](std::vector<std::string> ss) {
assert(!command);
auto i = commands.find(ss[0]);
diff --git a/src/nix/command.hh b/src/nix/command.hh
index 2db22dba2..be56f8992 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -182,7 +182,7 @@ public:
std::shared_ptr<Command> command;
- MultiCommand(const Commands & commands);
+ MultiCommand(const std::vector<ref<Command>> & commands);
void printHelp(const string & programName, std::ostream & out) override;
@@ -194,12 +194,12 @@ public:
/* A helper class for registering commands globally. */
struct RegisterCommand
{
- static Commands * commands;
+ static std::vector<ref<Command>> * commands;
RegisterCommand(ref<Command> command)
{
- if (!commands) commands = new Commands;
- commands->emplace(command->name(), command);
+ if (!commands) commands = new std::vector<ref<Command>>;
+ commands->push_back(command);
}
};
diff --git a/src/nix/main.cc b/src/nix/main.cc
index 1c9d909d8..d5cba7fb9 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -104,10 +104,15 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
"--help-config' for a list of configuration settings.\n";
}
+ void printHelp(const string & programName, std::ostream & out)
+ {
+ MultiCommand::printHelp(programName, out);
+ std::cout << "\nNote: this program is EXPERIMENTAL and subject to change.\n";
+ }
+
void showHelpAndExit()
{
printHelp(programName, std::cout);
- std::cout << "\nNote: this program is EXPERIMENTAL and subject to change.\n";
throw Exit();
}
};