diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-02-09 21:07:48 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-02-09 21:07:48 +0100 |
commit | 0db9e6cd1af299f7d65e0b99019f0ccdbb1aaf3f (patch) | |
tree | 78e8c206bef0ac59146157c1b35b5c92af0bb819 /src/libmain/common-args.cc | |
parent | c780c1124ec6711f09b9855c3b574b6655af6625 (diff) |
New command line parsing infrastructure
Diffstat (limited to 'src/libmain/common-args.cc')
-rw-r--r-- | src/libmain/common-args.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/libmain/common-args.cc b/src/libmain/common-args.cc new file mode 100644 index 000000000..54dbb1da3 --- /dev/null +++ b/src/libmain/common-args.cc @@ -0,0 +1,37 @@ +#include "common-args.hh" +#include "globals.hh" + +namespace nix { + +MixCommonArgs::MixCommonArgs(const string & programName) +{ + mkFlag('v', "verbose", "increase verbosity level", []() { + verbosity = (Verbosity) (verbosity + 1); + }); + + mkFlag(0, "quiet", "decrease verbosity level", []() { + verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; + }); + + mkFlag(0, "debug", "enable debug output", []() { + verbosity = lvlDebug; + }); + + mkFlag1(0, "log-type", "type", "set logging format ('pretty', 'flat', 'systemd')", + [](std::string s) { + if (s == "pretty") logType = ltPretty; + else if (s == "escapes") logType = ltEscapes; + else if (s == "flat") logType = ltFlat; + else if (s == "systemd") logType = ltSystemd; + else throw UsageError("unknown log type"); + }); + + mkFlag(0, "option", {"name", "value"}, "set a Nix configuration option (overriding nix.conf)", 2, + [](Strings ss) { + auto name = ss.front(); ss.pop_front(); + auto value = ss.front(); + settings.set(name, value); + }); +} + +} |