util.prosodyctl.shell: Add :method syntax to make e.g. MUC commands easier
authorKim Alvefur <zash@zash.se>
Sat, 09 Dec 2023 16:25:04 +0100
changeset 13400 16413bc29361
parent 13399 1675d4b6363a
child 13401 517a335269ef
util.prosodyctl.shell: Add :method syntax to make e.g. MUC commands easier e.g. prosodyctl shell muc room room@muc.example.com :set_name "This Room"
util/prosodyctl/shell.lua
--- a/util/prosodyctl/shell.lua	Sat Dec 09 15:15:06 2023 +0100
+++ b/util/prosodyctl/shell.lua	Sat Dec 09 16:25:04 2023 +0100
@@ -80,8 +80,17 @@
 
 	if arg[1] then
 		if arg[2] then
-			-- prosodyctl shell module reload foo bar.com --> module:reload("foo", "bar.com")
-			arg[1] = string.format("%s:%s("..string.rep("%q", #arg-2,", ")..")", unpack(arg));
+			local fmt = { "%s"; ":%s("; ")" };
+			for i = 3, #arg do
+				if arg[i]:sub(1, 1) == ":" then
+					table.insert(fmt, i, ")%s(");
+				elseif i > 3 and fmt[i - 1] == "%q" then
+					table.insert(fmt, i, ", %q");
+				else
+					table.insert(fmt, i, "%q");
+				end
+			end
+			arg[1] = string.format(table.concat(fmt), table.unpack(arg));
 		end
 
 		client.events.add_handler("connected", function()