lix/src/libmain/common-args.cc

90 lines
2.7 KiB
C++
Raw Normal View History

#include "common-args.hh"
#include "globals.hh"
#include "loggers.hh"
namespace nix {
MixCommonArgs::MixCommonArgs(const string & programName)
: programName(programName)
{
2020-05-04 20:40:19 +00:00
addFlag({
.longName = "verbose",
.shortName = 'v',
.description = "Increase the logging verbosity level.",
2021-01-25 18:03:13 +00:00
.category = loggingCategory,
2020-05-04 20:40:19 +00:00
.handler = {[]() { verbosity = (Verbosity) (verbosity + 1); }},
});
addFlag({
.longName = "quiet",
.description = "Decrease the logging verbosity level.",
2021-01-25 18:03:13 +00:00
.category = loggingCategory,
2020-05-04 20:40:19 +00:00
.handler = {[]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; }},
});
addFlag({
.longName = "debug",
.description = "Set the logging verbosity level to 'debug'.",
2021-01-25 18:03:13 +00:00
.category = loggingCategory,
2020-05-04 20:40:19 +00:00
.handler = {[]() { verbosity = lvlDebug; }},
});
addFlag({
.longName = "option",
.description = "Set the Nix configuration setting *name* to *value* (overriding `nix.conf`).",
2020-05-04 20:40:19 +00:00
.labels = {"name", "value"},
.handler = {[](std::string name, std::string value) {
try {
2020-05-04 20:40:19 +00:00
globalConfig.set(name, value);
} catch (UsageError & e) {
2020-05-10 18:32:21 +00:00
if (!completions)
warn(e.what());
}
2020-05-04 20:40:19 +00:00
}},
2020-05-10 19:50:32 +00:00
.completer = [](size_t index, std::string_view prefix) {
if (index == 0) {
std::map<std::string, Config::SettingInfo> settings;
globalConfig.getSettings(settings);
for (auto & s : settings)
if (hasPrefix(s.first, prefix))
completions->add(s.first, fmt("Set the `%s` setting.", s.first));
2020-05-10 19:50:32 +00:00
}
}
2020-05-04 20:40:19 +00:00
});
addFlag({
.longName = "log-format",
.description = "Set the format of log output; one of `raw`, `internal-json`, `bar` or `bar-with-logs`.",
2021-01-25 18:03:13 +00:00
.category = loggingCategory,
.labels = {"format"},
.handler = {[](std::string format) { setLogFormat(format); }},
});
2020-05-04 20:40:19 +00:00
addFlag({
.longName = "max-jobs",
.shortName = 'j',
.description = "The maximum number of parallel builds.",
2020-05-04 20:40:19 +00:00
.labels = Strings{"jobs"},
.handler = {[=](std::string s) {
2019-06-15 14:34:06 +00:00
settings.set("max-jobs", s);
2020-05-04 20:40:19 +00:00
}}
});
2019-06-15 14:34:06 +00:00
2021-01-25 18:03:13 +00:00
std::string cat = "Options to override configuration settings";
globalConfig.convertToArgs(*this, cat);
// Backward compatibility hack: nix-env already had a --system flag.
if (programName == "nix-env") longFlags.erase("system");
hiddenCategories.insert(cat);
}
void MixCommonArgs::initialFlagsProcessed()
{
initPlugins();
pluginsInited();
}
}