mirror of
https://github.com/NixOS/nix
synced 2025-06-29 02:11:15 +02:00
New command line parsing infrastructure
This commit is contained in:
parent
c780c1124e
commit
0db9e6cd1a
6 changed files with 472 additions and 81 deletions
37
src/libmain/common-args.cc
Normal file
37
src/libmain/common-args.cc
Normal file
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue