diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-04-21 14:34:46 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-04-21 14:34:46 +0200 |
commit | 1b0088ebb226ab80c91b54c201cc70204b976310 (patch) | |
tree | 52f851fa6e91512a6e4351f104c4cfa7673957c6 | |
parent | ddea253ff8312bf1d2559999c4dd8d9cc3e5b240 (diff) |
nix --help: Show short flags
-rw-r--r-- | src/libutil/args.cc | 7 | ||||
-rw-r--r-- | src/libutil/args.hh | 3 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 6e4b82a27..115484f9e 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 4469a046d..6aa08aaca 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; } |