mod_admin_shell: Add config:set([host,] key, value) because why not
authorKim Alvefur <zash@zash.se>
Sat, 08 Apr 2023 11:28:55 +0200
changeset 13066 da51c36ed1e7
parent 13065 7e0bb5154f3b
child 13067 414952def2d3
mod_admin_shell: Add config:set([host,] key, value) because why not We had config:get() but not this. > <MattJ> Yeah, why did we never implement that? Handy if you want to quickly try out settings without reloading the whole config.
plugins/mod_admin_shell.lua
--- a/plugins/mod_admin_shell.lua	Sat Apr 08 10:16:18 2023 +0200
+++ b/plugins/mod_admin_shell.lua	Sat Apr 08 11:28:55 2023 +0200
@@ -313,6 +313,7 @@
 	elseif section == "config" then
 		print [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]]
 		print [[config:get([host,] option) - Show the value of a config option.]]
+		print [[config:set([host,] option, value) - Update the value of a config option without writing to the config file.]]
 	elseif section == "stats" then -- luacheck: ignore 542
 		print [[stats:show(pattern) - Show internal statistics, optionally filtering by name with a pattern]]
 		print [[stats:show():cfgraph() - Show a cumulative frequency graph]]
@@ -712,6 +713,13 @@
 	return true, serialize_config(config_get(host, key));
 end
 
+function def_env.config:set(host, key, value)
+	if host ~= "*" and not prosody.hosts[host] then
+		host, key, value = "*", host, key;
+	end
+	return require "prosody.core.configmanager".set(host, key, value);
+end
+
 function def_env.config:reload()
 	local ok, err = prosody.reload_config();
 	return ok, (ok and "Config reloaded (you may need to reload modules to take effect)") or tostring(err);