diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-06-07T16·41+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-06-07T16·41+0200 |
commit | 186571965dccf57d15b9f37c1cca92a57187b7b3 (patch) | |
tree | 79c38bc54d9a3e2bbd296a094ca988c13088fb09 /src/libutil/args.cc | |
parent | aa952d5f0bc623a1584f2d589209f586e594c75f (diff) |
Don't show flags from config settings in "nix --help"
Diffstat (limited to 'src/libutil/args.cc')
-rw-r--r-- | src/libutil/args.cc | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 115484f9e6c7..df7e040875d6 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -3,6 +3,18 @@ namespace nix { +Args::FlagMaker Args::mkFlag() +{ + return FlagMaker(*this); +} + +Args::FlagMaker::~FlagMaker() +{ + assert(flag->longName != ""); + args.longFlags[flag->longName] = flag; + if (flag->shortName) args.shortFlags[flag->shortName] = flag; +} + void Args::parseCmdline(const Strings & _cmdline) { Strings pendingArgs; @@ -71,11 +83,13 @@ void Args::printHelp(const string & programName, std::ostream & out) void Args::printFlags(std::ostream & out) { Table2 table; - for (auto & flag : longFlags) + for (auto & flag : longFlags) { + if (hiddenCategories.count(flag.second->category)) continue; table.push_back(std::make_pair( - (flag.second.shortName ? std::string("-") + flag.second.shortName + ", " : " ") - + "--" + flag.first + renderLabels(flag.second.labels), - flag.second.description)); + (flag.second->shortName ? std::string("-") + flag.second->shortName + ", " : " ") + + "--" + flag.first + renderLabels(flag.second->labels), + flag.second->description)); + } printTable(out, table); } @@ -99,14 +113,14 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end) if (string(*pos, 0, 2) == "--") { auto i = longFlags.find(string(*pos, 2)); if (i == longFlags.end()) return false; - return process("--" + i->first, i->second); + return process("--" + i->first, *i->second); } if (string(*pos, 0, 1) == "-" && pos->size() == 2) { auto c = (*pos)[1]; auto i = shortFlags.find(c); if (i == shortFlags.end()) return false; - return process(std::string("-") + c, i->second); + return process(std::string("-") + c, *i->second); } return false; |