aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-01-16 20:40:14 +0100
committerKim Alvefur <zash@zash.se>2021-01-16 20:40:14 +0100
commitc4abd68e92a258750177f25dca38525fe3133063 (patch)
tree66bca82b3f98fd03feb4fd2c7b7611e46a0445c3 /core
parent5b7a569fe072fbae5dd1f951fdad3a5c7d273e36 (diff)
downloadprosody-c4abd68e92a258750177f25dca38525fe3133063.tar.gz
prosody-c4abd68e92a258750177f25dca38525fe3133063.zip
moduleapi: Add enum config option method
For when a setting has a few fixed values it can take
Diffstat (limited to 'core')
-rw-r--r--core/features.lua3
-rw-r--r--core/moduleapi.lua9
2 files changed, 12 insertions, 0 deletions
diff --git a/core/features.lua b/core/features.lua
index c96f0c81..2948a1a7 100644
--- a/core/features.lua
+++ b/core/features.lua
@@ -15,5 +15,8 @@ return {
-- prosody:guest, prosody:registered, prosody:member
"split-user-roles";
+
+ -- new moduleapi methods
+ "getopt-enum";
};
};
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 3ee8647f..68818b8d 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -310,6 +310,15 @@ function api:get_option_path(name, default, parent)
return resolve_relative_path(parent, value);
end
+function api:get_option_enum(name, default, ...)
+ local value = self:get_option_scalar(name, default);
+ if value == nil then return nil; end
+ local options = set.new{default, ...};
+ if not options:contains(value) then
+ self:log("error", "Config option '%s' not in set of allowed values (one of: %s)", name, options);
+ end
+ return value;
+end
function api:context(host)
return setmetatable({ host = host or "*", global = "*" == host }, { __index = self, __newindex = self });