mirror of
https://github.com/NixOS/nix.git
synced 2025-11-16 07:22:43 +01:00
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge. Co-authored-by: Graham Christensen <graham@grahamc.com>
69 lines
1.7 KiB
C++
69 lines
1.7 KiB
C++
#include "nix/util/config-global.hh"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
namespace nix {
|
|
|
|
bool GlobalConfig::set(const std::string & name, const std::string & value)
|
|
{
|
|
for (auto & config : *configRegistrations)
|
|
if (config->set(name, value))
|
|
return true;
|
|
|
|
unknownSettings.emplace(name, value);
|
|
|
|
return false;
|
|
}
|
|
|
|
void GlobalConfig::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly)
|
|
{
|
|
for (auto & config : *configRegistrations)
|
|
config->getSettings(res, overriddenOnly);
|
|
}
|
|
|
|
void GlobalConfig::resetOverridden()
|
|
{
|
|
for (auto & config : *configRegistrations)
|
|
config->resetOverridden();
|
|
}
|
|
|
|
nlohmann::json GlobalConfig::toJSON()
|
|
{
|
|
auto res = nlohmann::json::object();
|
|
for (const auto & config : *configRegistrations)
|
|
res.update(config->toJSON());
|
|
return res;
|
|
}
|
|
|
|
std::string GlobalConfig::toKeyValue()
|
|
{
|
|
std::string res;
|
|
std::map<std::string, Config::SettingInfo> settings;
|
|
globalConfig.getSettings(settings);
|
|
for (const auto & s : settings)
|
|
res += fmt("%s = %s\n", s.first, s.second.value);
|
|
return res;
|
|
}
|
|
|
|
void GlobalConfig::convertToArgs(Args & args, const std::string & category)
|
|
{
|
|
for (auto & config : *configRegistrations)
|
|
config->convertToArgs(args, category);
|
|
}
|
|
|
|
GlobalConfig globalConfig;
|
|
|
|
GlobalConfig::ConfigRegistrations * GlobalConfig::configRegistrations;
|
|
|
|
GlobalConfig::Register::Register(Config * config)
|
|
{
|
|
if (!configRegistrations)
|
|
configRegistrations = new ConfigRegistrations;
|
|
configRegistrations->emplace_back(config);
|
|
}
|
|
|
|
ExperimentalFeatureSettings experimentalFeatureSettings;
|
|
|
|
static GlobalConfig::Register rSettings(&experimentalFeatureSettings);
|
|
|
|
} // namespace nix
|