diff options
author | regnat <rg@regnat.ovh> | 2020-09-09 11:35:33 +0200 |
---|---|---|
committer | regnat <rg@regnat.ovh> | 2020-09-16 13:53:08 +0200 |
commit | 3c525d15903ea98e5401ff57061295b8c625cc45 (patch) | |
tree | 08b4a56d9b02b1d18b296e1b86a4108130e5d3da /src/libutil/config.cc | |
parent | 3b57181f8ed94cfa149ad4319ba96d41c5fbc30e (diff) |
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..)
Diffstat (limited to 'src/libutil/config.cc')
-rw-r--r-- | src/libutil/config.cc | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 3cf720bce..faa5cdbeb 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -137,11 +137,7 @@ nlohmann::json Config::toJSON() auto res = nlohmann::json::object(); for (auto & s : _settings) if (!s.second.isAlias) { - auto obj = nlohmann::json::object(); - 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); + res.emplace(s.first, s.second.setting->toJSON()); } return res; } @@ -168,17 +164,19 @@ void AbstractSetting::setDefault(const std::string & str) nlohmann::json AbstractSetting::toJSON() { - return to_string(); + return nlohmann::json(toJSONObject()); } -void AbstractSetting::convertToArg(Args & args, const std::string & category) +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; } -template<typename T> -nlohmann::json BaseSetting<T>::toJSON() +void AbstractSetting::convertToArg(Args & args, const std::string & category) { - return value; } template<typename T> @@ -259,11 +257,6 @@ template<> std::string BaseSetting<Strings>::to_string() const return concatStringsSep(" ", value); } -template<> nlohmann::json BaseSetting<Strings>::toJSON() -{ - return value; -} - template<> void BaseSetting<StringSet>::set(const std::string & str) { value = tokenizeString<StringSet>(str); @@ -274,11 +267,6 @@ template<> std::string BaseSetting<StringSet>::to_string() const return concatStringsSep(" ", value); } -template<> nlohmann::json BaseSetting<StringSet>::toJSON() -{ - return value; -} - template class BaseSetting<int>; template class BaseSetting<unsigned int>; template class BaseSetting<long>; |