1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 22:01:15 +02:00

Generate the nix.conf docs from the source code

This means we don't have two (divergent) sets of option descriptions
anymore.
This commit is contained in:
Eelco Dolstra 2020-08-19 18:28:04 +02:00
parent 34b22e0123
commit c8fa39324a
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
10 changed files with 802 additions and 834 deletions

View file

@ -149,11 +149,48 @@ void Config::convertToArgs(Args & args, const std::string & category)
s.second.setting->convertToArg(args, category);
}
static std::string stripIndentation(std::string_view s)
{
size_t minIndent = 10000;
size_t curIndent = 0;
bool atStartOfLine = true;
for (auto & c : s) {
if (atStartOfLine && c == ' ')
curIndent++;
else if (c == '\n') {
if (atStartOfLine)
minIndent = std::max(minIndent, curIndent);
curIndent = 0;
atStartOfLine = true;
} else {
if (atStartOfLine) {
minIndent = std::min(minIndent, curIndent);
atStartOfLine = false;
}
}
}
std::string res;
size_t pos = 0;
while (pos < s.size()) {
auto eol = s.find('\n', pos);
if (eol == s.npos) eol = s.size();
if (eol - pos > minIndent)
res.append(s.substr(pos + minIndent, eol - pos - minIndent));
res.push_back('\n');
pos = eol + 1;
}
return res;
}
AbstractSetting::AbstractSetting(
const std::string & name,
const std::string & description,
const std::set<std::string> & aliases)
: name(name), description(description), aliases(aliases)
: name(name), description(stripIndentation(description)), aliases(aliases)
{
}

View file

@ -37,10 +37,12 @@ typedef uint64_t ActivityId;
struct LoggerSettings : Config
{
Setting<bool> showTrace{this,
false,
"show-trace",
"Whether to show a stack trace on evaluation errors."};
Setting<bool> showTrace{
this, false, "show-trace",
R"(
Where Nix should print out a stack trace in case of Nix
expression evaluation errors.
)"};
};
extern LoggerSettings loggerSettings;