about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-21T12·34+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-21T12·34+0200
commit1b0088ebb226ab80c91b54c201cc70204b976310 (patch)
tree52f851fa6e91512a6e4351f104c4cfa7673957c6 /src
parentddea253ff8312bf1d2559999c4dd8d9cc3e5b240 (diff)
nix --help: Show short flags
Diffstat (limited to 'src')
-rw-r--r--src/libutil/args.cc7
-rw-r--r--src/libutil/args.hh3
2 files changed, 6 insertions, 4 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index 6e4b82a279ce..115484f9e6c7 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -71,10 +71,11 @@ void Args::printHelp(const string & programName, std::ostream & out)
 void Args::printFlags(std::ostream & out)
 {
     Table2 table;
-    for (auto & flags : longFlags)
+    for (auto & flag : longFlags)
         table.push_back(std::make_pair(
-                "--" + flags.first + renderLabels(flags.second.labels),
-                flags.second.description));
+                (flag.second.shortName ? std::string("-") + flag.second.shortName + ", " : "    ")
+                + "--" + flag.first + renderLabels(flag.second.labels),
+                flag.second.description));
     printTable(out, table);
 }
 
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index 4469a046d28a..6aa08aacac9e 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -29,6 +29,7 @@ protected:
     /* Flags. */
     struct Flag
     {
+        char shortName;
         std::string description;
         Strings labels;
         size_t arity;
@@ -63,7 +64,7 @@ public:
         const Strings & labels, const std::string & description,
         size_t arity, std::function<void(Strings)> handler)
     {
-        auto flag = Flag{description, labels, arity, handler};
+        auto flag = Flag{shortName, description, labels, arity, handler};
         if (shortName) shortFlags[shortName] = flag;
         longFlags[longName] = flag;
     }