about summary refs log tree commit diff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/command.cc2
-rw-r--r--src/nix/main.cc15
2 files changed, 10 insertions, 7 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index 3c82e0df57f7..96b685a5b2eb 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -24,7 +24,7 @@ void Command::printHelp(const string & programName, std::ostream & out)
 MultiCommand::MultiCommand(const Commands & _commands)
     : commands(_commands)
 {
-    expectedArgs.push_back(ExpectedArg{"command", 1, [=](Strings ss) {
+    expectedArgs.push_back(ExpectedArg{"command", 1, true, [=](Strings ss) {
         assert(!command);
         auto i = commands.find(ss.front());
         if (i == commands.end())
diff --git a/src/nix/main.cc b/src/nix/main.cc
index 88a602b84813..4b51c5ee14a0 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -15,11 +15,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
 {
     NixArgs() : MultiCommand(*RegisterCommand::commands), MixCommonArgs("nix")
     {
-        mkFlag('h', "help", "show usage information", [=]() {
-            printHelp(programName, std::cout);
-            std::cout << "\nNote: this program is EXPERIMENTAL and subject to change.\n";
-            throw Exit();
-        });
+        mkFlag('h', "help", "show usage information", [&]() { showHelpAndExit(); });
 
         mkFlag(0, "help-config", "show configuration options", [=]() {
             std::cout << "The following configuration options are available:\n\n";
@@ -47,6 +43,13 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
             "Boolean settings can be overriden using ‘--<name>’ or ‘--no-<name>’. See ‘nix\n"
             "--help-config’ for a list of configuration settings.\n";
     }
+
+    void showHelpAndExit()
+    {
+        printHelp(programName, std::cout);
+        std::cout << "\nNote: this program is EXPERIMENTAL and subject to change.\n";
+        throw Exit();
+    }
 };
 
 void mainWrapped(int argc, char * * argv)
@@ -68,7 +71,7 @@ void mainWrapped(int argc, char * * argv)
 
     args.parseCmdline(argvToStrings(argc, argv));
 
-    assert(args.command);
+    if (!args.command) args.showHelpAndExit();
 
     StartProgressBar bar;