aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2025-02-17 17:02:35 +0000
committerMatthew Wild <mwild1@gmail.com>2025-02-17 17:02:35 +0000
commit79381510cfc470cbe8af57b05c4dfd27b12f55d2 (patch)
tree623def245524b527f1e7cfbf2e298642eb7e0779 /util
parentedafb195e121856ea46894a20a9e0946a3eebddc (diff)
downloadprosody-79381510cfc470cbe8af57b05c4dfd27b12f55d2.tar.gz
prosody-79381510cfc470cbe8af57b05c4dfd27b12f55d2.zip
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
This allow a shell-command to provide a 'flags' field, which will automatically cause the parameters to be fed through argparse. The rationale is to make it easier for more complex commands to be invoked from the command line (`prosodyctl shell foo bar ...`). Until now they were limited to accepting a list of strings, and any complex argument processing was non-standard and awkward to implement.
Diffstat (limited to 'util')
-rw-r--r--util/prosodyctl/shell.lua12
1 files changed, 1 insertions, 11 deletions
diff --git a/util/prosodyctl/shell.lua b/util/prosodyctl/shell.lua
index a0fbb09c..d72cf294 100644
--- a/util/prosodyctl/shell.lua
+++ b/util/prosodyctl/shell.lua
@@ -87,17 +87,7 @@ local function start(arg) --luacheck: ignore 212/arg
if arg[1] then
if arg[2] then
- 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]:match("%%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));
+ arg[1] = ("{"..string.rep("%q", #arg, ", ").."}"):format(table.unpack(arg, 1, #arg));
end
client.events.add_handler("connected", function()