aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-03-09 14:00:43 -0800
committerRebecca Turner <rbt@sent.as>2024-04-07 18:22:15 -0700
commit6f863e8ccd44342e7650f612b46893b605755000 (patch)
tree349b2f44a3303cd4e9e65db3edd5f17bdfddcce4 /src
parent06e11778b594931b24d256a0a68ccea6533c6b48 (diff)
Add `PathsSetting`
Change-Id: I1165f6ef033a5f757ca3716d3f8008ba36b01fd0
Diffstat (limited to 'src')
-rw-r--r--src/libutil/config.cc28
-rw-r--r--src/libutil/config.hh20
2 files changed, 48 insertions, 0 deletions
diff --git a/src/libutil/config.cc b/src/libutil/config.cc
index 8e76d6d66..81efcd507 100644
--- a/src/libutil/config.cc
+++ b/src/libutil/config.cc
@@ -437,6 +437,34 @@ void OptionalPathSetting::operator =(const std::optional<Path> & v)
this->assign(v);
}
+PathsSetting::PathsSetting(Config * options,
+ const Paths & def,
+ const std::string & name,
+ const std::string & description,
+ const std::set<std::string> & aliases)
+ : BaseSetting<Paths>(def, true, name, description, aliases)
+{
+ options->addSetting(this);
+}
+
+
+Paths PathsSetting::parse(const std::string & str) const
+{
+ auto strings = tokenizeString<Strings>(str);
+ Paths parsed;
+
+ for (auto str : strings) {
+ parsed.push_back(canonPath(str));
+ }
+
+ return parsed;
+}
+
+PathsSetting::operator bool() const noexcept
+{
+ return !get().empty();
+}
+
bool GlobalConfig::set(const std::string & name, const std::string & value)
{
for (auto & config : *configRegistrations)
diff --git a/src/libutil/config.hh b/src/libutil/config.hh
index 3e232d224..01e1239b3 100644
--- a/src/libutil/config.hh
+++ b/src/libutil/config.hh
@@ -375,6 +375,26 @@ public:
void operator =(const std::optional<Path> & v);
};
+/**
+ * Like `OptionalPathSetting`, but allows multiple paths.
+ */
+class PathsSetting : public BaseSetting<Paths>
+{
+public:
+
+ PathsSetting(Config * options,
+ const Paths & def,
+ const std::string & name,
+ const std::string & description,
+ const std::set<std::string> & aliases = {});
+
+ Paths parse(const std::string & str) const override;
+
+ void operator =(const Paths & v);
+
+ operator bool() const noexcept;
+};
+
struct GlobalConfig : public AbstractConfig
{
typedef std::vector<Config*> ConfigRegistrations;