util.prosodyctl.shell: Allow calling console commands with fewer shell quotes
authorKim Alvefur <zash@zash.se>
Sun, 25 Apr 2021 17:20:58 +0200
changeset 11524 0a464a6e88c4
parent 11523 df4bd3af4099
child 11525 16caf35f031f
util.prosodyctl.shell: Allow calling console commands with fewer shell quotes E.g. `prosodyctl shell module reload disco example.com` becomes equivalent to `prosodyctl shell 'module:reload("disco", "example.com")`. Won't work for every possible command, but reduces the amount of shell quoting problems for most common commands.
util/prosodyctl/shell.lua
--- a/util/prosodyctl/shell.lua	Thu Apr 15 15:57:24 2021 +0200
+++ b/util/prosodyctl/shell.lua	Sun Apr 25 17:20:58 2021 +0200
@@ -73,9 +73,8 @@
 
 	if arg[1] then
 		if arg[2] then
-			-- TODO send each arg[] and wait for reply?
-			print("Only one command is supported as argument");
-			os.exit(1);
+			-- prosodyctl shell module reload foo bar.com --> module:reload("foo", "bar.com")
+			arg[1] = string.format("%s:%s("..string.rep("%q", #arg-2, ", ")..")", table.unpack(arg));
 		end
 
 		client.events.add_handler("connected", function()