about summary refs log tree commit diff
path: root/src/nix/main.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-07-14T11·44+0200
committerEelco Dolstra <edolstra@gmail.com>2017-07-14T11·44+0200
commit112ff7833d4f3a233755b2fe856b2eb2b3723254 (patch)
treed07eb31bc6e67c48aa3bd1d0ddaf7f4a6e70f0e4 /src/nix/main.cc
parent38374a9d35765a1c0b78bfeb02e6f22fc8643e83 (diff)
nix: Show help when no arguments are given
Fixes #1464.
Diffstat (limited to 'src/nix/main.cc')
-rw-r--r--src/nix/main.cc15
1 files changed, 9 insertions, 6 deletions
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;