From bd108b7e617f43350ebb7ea69cd36a55edc7e8bb Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Mon, 2 Mar 2026 19:11:14 +0100 Subject: [PATCH] libutil/config: support optional This is going to be used in the extra-local-job future setting. Change-Id: Ied76f32b8fa97cb71691d76167103001aa14fa01 Signed-off-by: Raito Bezarius --- lix/libutil/config-impl.hh | 1 + lix/libutil/config.cc | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lix/libutil/config-impl.hh b/lix/libutil/config-impl.hh index d25ec5fd1..7c9a5aa1e 100644 --- a/lix/libutil/config-impl.hh +++ b/lix/libutil/config-impl.hh @@ -127,6 +127,7 @@ void BaseSetting::convertToArg(Args & args, const std::string & category) DECLARE_CONFIG_SERIALISER(std::string) DECLARE_CONFIG_SERIALISER(std::optional) DECLARE_CONFIG_SERIALISER(std::optional) +DECLARE_CONFIG_SERIALISER(std::optional) DECLARE_CONFIG_SERIALISER(bool) DECLARE_CONFIG_SERIALISER(Strings) DECLARE_CONFIG_SERIALISER(StringSet) diff --git a/lix/libutil/config.cc b/lix/libutil/config.cc index fe0be4408..3948eee94 100644 --- a/lix/libutil/config.cc +++ b/lix/libutil/config.cc @@ -181,11 +181,30 @@ template<> std::optional BaseSetting>::parse(c throw UsageError("setting '%s' has invalid value '%s'", name, str); } +template<> +std::optional +BaseSetting>::parse(const std::string & str, const ApplyConfigOptions & options) const +{ + if (str == "") { + return std::nullopt; + } else if (auto n = string2Int(str)) { + return n; + } else { + throw UsageError("setting '%s' has invalid value '%s'", name, str); + } +} + template<> std::string BaseSetting>::to_string() const { return value ? std::to_string(*value) : ""; } +template<> +std::string BaseSetting>::to_string() const +{ + return value ? std::to_string(*value) : ""; +} + template<> bool BaseSetting::parse(const std::string & str, const ApplyConfigOptions & options) const { if (str == "true" || str == "yes" || str == "1")