mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
Complete the toJSON
instance for Setting<T>
Don't let it just contain the value, but also the other fields of the setting (description, aliases, etc..)
This commit is contained in:
parent
3b57181f8e
commit
3c525d1590
3 changed files with 19 additions and 29 deletions
|
@ -162,11 +162,6 @@ template<> std::string BaseSetting<SandboxMode>::to_string() const
|
||||||
else abort();
|
else abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> nlohmann::json BaseSetting<SandboxMode>::toJSON()
|
|
||||||
{
|
|
||||||
return AbstractSetting::toJSON();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::string & category)
|
template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::string & category)
|
||||||
{
|
{
|
||||||
args.addFlag({
|
args.addFlag({
|
||||||
|
|
|
@ -137,11 +137,7 @@ nlohmann::json Config::toJSON()
|
||||||
auto res = nlohmann::json::object();
|
auto res = nlohmann::json::object();
|
||||||
for (auto & s : _settings)
|
for (auto & s : _settings)
|
||||||
if (!s.second.isAlias) {
|
if (!s.second.isAlias) {
|
||||||
auto obj = nlohmann::json::object();
|
res.emplace(s.first, s.second.setting->toJSON());
|
||||||
obj.emplace("description", s.second.setting->description);
|
|
||||||
obj.emplace("aliases", s.second.setting->aliases);
|
|
||||||
obj.emplace("value", s.second.setting->toJSON());
|
|
||||||
res.emplace(s.first, obj);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -168,19 +164,21 @@ void AbstractSetting::setDefault(const std::string & str)
|
||||||
|
|
||||||
nlohmann::json AbstractSetting::toJSON()
|
nlohmann::json AbstractSetting::toJSON()
|
||||||
{
|
{
|
||||||
return to_string();
|
return nlohmann::json(toJSONObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, nlohmann::json> AbstractSetting::toJSONObject()
|
||||||
|
{
|
||||||
|
std::map<std::string, nlohmann::json> obj;
|
||||||
|
obj.emplace("description", description);
|
||||||
|
obj.emplace("aliases", aliases);
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractSetting::convertToArg(Args & args, const std::string & category)
|
void AbstractSetting::convertToArg(Args & args, const std::string & category)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
nlohmann::json BaseSetting<T>::toJSON()
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void BaseSetting<T>::convertToArg(Args & args, const std::string & category)
|
void BaseSetting<T>::convertToArg(Args & args, const std::string & category)
|
||||||
{
|
{
|
||||||
|
@ -259,11 +257,6 @@ template<> std::string BaseSetting<Strings>::to_string() const
|
||||||
return concatStringsSep(" ", value);
|
return concatStringsSep(" ", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> nlohmann::json BaseSetting<Strings>::toJSON()
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> void BaseSetting<StringSet>::set(const std::string & str)
|
template<> void BaseSetting<StringSet>::set(const std::string & str)
|
||||||
{
|
{
|
||||||
value = tokenizeString<StringSet>(str);
|
value = tokenizeString<StringSet>(str);
|
||||||
|
@ -274,11 +267,6 @@ template<> std::string BaseSetting<StringSet>::to_string() const
|
||||||
return concatStringsSep(" ", value);
|
return concatStringsSep(" ", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> nlohmann::json BaseSetting<StringSet>::toJSON()
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
template class BaseSetting<int>;
|
template class BaseSetting<int>;
|
||||||
template class BaseSetting<unsigned int>;
|
template class BaseSetting<unsigned int>;
|
||||||
template class BaseSetting<long>;
|
template class BaseSetting<long>;
|
||||||
|
|
|
@ -206,7 +206,9 @@ protected:
|
||||||
|
|
||||||
virtual std::string to_string() const = 0;
|
virtual std::string to_string() const = 0;
|
||||||
|
|
||||||
virtual nlohmann::json toJSON();
|
nlohmann::json toJSON();
|
||||||
|
|
||||||
|
virtual std::map<std::string, nlohmann::json> toJSONObject();
|
||||||
|
|
||||||
virtual void convertToArg(Args & args, const std::string & category);
|
virtual void convertToArg(Args & args, const std::string & category);
|
||||||
|
|
||||||
|
@ -251,7 +253,12 @@ public:
|
||||||
|
|
||||||
void convertToArg(Args & args, const std::string & category) override;
|
void convertToArg(Args & args, const std::string & category) override;
|
||||||
|
|
||||||
nlohmann::json toJSON() override;
|
std::map<std::string, nlohmann::json> toJSONObject() override
|
||||||
|
{
|
||||||
|
auto obj = AbstractSetting::toJSONObject();
|
||||||
|
obj.emplace("value", value);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
Loading…
Reference in a new issue