nix --help: Show short flags

This commit is contained in:
Eelco Dolstra 2016-04-21 14:34:46 +02:00
parent ddea253ff8
commit 1b0088ebb2
2 changed files with 6 additions and 4 deletions

View file

@ -71,10 +71,11 @@ void Args::printHelp(const string & programName, std::ostream & out)
void Args::printFlags(std::ostream & out) void Args::printFlags(std::ostream & out)
{ {
Table2 table; Table2 table;
for (auto & flags : longFlags) for (auto & flag : longFlags)
table.push_back(std::make_pair( table.push_back(std::make_pair(
"--" + flags.first + renderLabels(flags.second.labels), (flag.second.shortName ? std::string("-") + flag.second.shortName + ", " : " ")
flags.second.description)); + "--" + flag.first + renderLabels(flag.second.labels),
flag.second.description));
printTable(out, table); printTable(out, table);
} }

View file

@ -29,6 +29,7 @@ protected:
/* Flags. */ /* Flags. */
struct Flag struct Flag
{ {
char shortName;
std::string description; std::string description;
Strings labels; Strings labels;
size_t arity; size_t arity;
@ -63,7 +64,7 @@ public:
const Strings & labels, const std::string & description, const Strings & labels, const std::string & description,
size_t arity, std::function<void(Strings)> handler) 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; if (shortName) shortFlags[shortName] = flag;
longFlags[longName] = flag; longFlags[longName] = flag;
} }