diff options
Diffstat (limited to 'src/libutil/config.cc')
-rw-r--r-- | src/libutil/config.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libutil/config.cc b/src/libutil/config.cc index f7a46bfee..612fb6e68 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -115,6 +115,13 @@ void Config::toJSON(JSONObject & out) } } +void Config::convertToArgs(Args & args) +{ + for (auto & s : _settings) + if (!s.second.isAlias) + s.second.setting->convertToArg(args); +} + AbstractSetting::AbstractSetting( const std::string & name, const std::string & description, @@ -128,12 +135,22 @@ void AbstractSetting::toJSON(JSONPlaceholder & out) out.write(to_string()); } +void AbstractSetting::convertToArg(Args & args) +{ +} + template<typename T> void BaseSetting<T>::toJSON(JSONPlaceholder & out) { out.write(value); } +template<typename T> +void BaseSetting<T>::convertToArg(Args & args) +{ + args.mkFlag(0, name, {}, description, 1, [=](Strings ss) { set(*ss.begin()); }); +} + template<> void BaseSetting<std::string>::set(const std::string & str) { value = str; @@ -174,6 +191,12 @@ template<> std::string BaseSetting<bool>::to_string() return value ? "true" : "false"; } +template<> void BaseSetting<bool>::convertToArg(Args & args) +{ + args.mkFlag(0, name, {}, description, 0, [=](Strings ss) { value = true; }); + args.mkFlag(0, "no-" + name, {}, description, 0, [=](Strings ss) { value = false; }); +} + template<> void BaseSetting<Strings>::set(const std::string & str) { value = tokenizeString<Strings>(str); @@ -216,6 +239,8 @@ template class BaseSetting<long long>; template class BaseSetting<unsigned long long>; template class BaseSetting<bool>; template class BaseSetting<std::string>; +template class BaseSetting<Strings>; +template class BaseSetting<StringSet>; void PathSetting::set(const std::string & str) { |