* Allow options from the Nix config file to be overriden from the
command line (e.g. "--option build-use-chroot true").
This commit is contained in:
parent
8ab6bc5a49
commit
60cb7de336
3 changed files with 21 additions and 0 deletions
|
@ -243,6 +243,13 @@ static void initAndRun(int argc, char * * argv)
|
||||||
maxSilentTime = getIntArg(arg, i, args.end());
|
maxSilentTime = getIntArg(arg, i, args.end());
|
||||||
else if (arg == "--no-build-hook")
|
else if (arg == "--no-build-hook")
|
||||||
useBuildHook = false;
|
useBuildHook = false;
|
||||||
|
else if (arg == "--option") {
|
||||||
|
++i; if (i == args.end()) throw UsageError("`--option' requires two arguments");
|
||||||
|
string name = *i;
|
||||||
|
++i; if (i == args.end()) throw UsageError("`--option' requires two arguments");
|
||||||
|
string value = *i;
|
||||||
|
overrideSetting(name, tokenizeString(value));
|
||||||
|
}
|
||||||
else remaining.push_back(arg);
|
else remaining.push_back(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@ static bool settingsRead = false;
|
||||||
|
|
||||||
static std::map<string, Strings> settings;
|
static std::map<string, Strings> settings;
|
||||||
|
|
||||||
|
/* Overriden settings. */
|
||||||
|
std::map<string, Strings> settingsCmdline;
|
||||||
|
|
||||||
|
|
||||||
string & at(Strings & ss, unsigned int n)
|
string & at(Strings & ss, unsigned int n)
|
||||||
{
|
{
|
||||||
|
@ -74,6 +77,8 @@ static void readSettings()
|
||||||
settings[name] = Strings(i, tokens.end());
|
settings[name] = Strings(i, tokens.end());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
settings.insert(settingsCmdline.begin(), settingsCmdline.end());
|
||||||
|
|
||||||
settingsRead = true;
|
settingsRead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +123,13 @@ unsigned int queryIntSetting(const string & name, unsigned int def)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void overrideSetting(const string & name, const Strings & value)
|
||||||
|
{
|
||||||
|
if (settingsRead) settings[name] = value;
|
||||||
|
settingsCmdline[name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void reloadSettings()
|
void reloadSettings()
|
||||||
{
|
{
|
||||||
settingsRead = false;
|
settingsRead = false;
|
||||||
|
|
|
@ -101,6 +101,8 @@ bool queryBoolSetting(const string & name, bool def);
|
||||||
|
|
||||||
unsigned int queryIntSetting(const string & name, unsigned int def);
|
unsigned int queryIntSetting(const string & name, unsigned int def);
|
||||||
|
|
||||||
|
void overrideSetting(const string & name, const Strings & value);
|
||||||
|
|
||||||
void reloadSettings();
|
void reloadSettings();
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue