about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-07-17T17·02+0200
committerEelco Dolstra <edolstra@gmail.com>2017-07-20T11·33+0200
commit90825dea518ea078f0783a72cc471a5b3716d198 (patch)
treeb6f6fed6e8c7a96a6769344060409f19a56290b9 /src/libutil
parent3162ad5ff497b92fc25cd3f397eaff01d67340cc (diff)
Add "nix search" command
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/args.cc1
-rw-r--r--src/libutil/args.hh4
2 files changed, 3 insertions, 2 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index 0eed4945418d..19a45d7e9b37 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -66,6 +66,7 @@ void Args::printHelp(const string & programName, std::ostream & out)
         std::cout << renderLabels({exp.label});
         // FIXME: handle arity > 1
         if (exp.arity == 0) std::cout << "...";
+        if (exp.optional) std::cout << "?";
     }
     std::cout << "\n";
 
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index ef8a7953e520..37e780dd1748 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -164,9 +164,9 @@ public:
     }
 
     /* Expect a string argument. */
-    void expectArg(const std::string & label, string * dest)
+    void expectArg(const std::string & label, string * dest, bool optional = false)
     {
-        expectedArgs.push_back(ExpectedArg{label, 1, false, [=](Strings ss) {
+        expectedArgs.push_back(ExpectedArg{label, 1, optional, [=](Strings ss) {
             *dest = ss.front();
         }});
     }