Comparison

util/prosodyctl/shell.lua @ 13396:16413bc29361

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"
author Kim Alvefur <zash@zash.se>
date Sat, 09 Dec 2023 16:25:04 +0100
parent 13052:585bd71a1a97
child 13398:4ba11c2b915a
comparison
equal deleted inserted replaced
13395:1675d4b6363a 13396:16413bc29361
78 os.exit(1); 78 os.exit(1);
79 end 79 end
80 80
81 if arg[1] then 81 if arg[1] then
82 if arg[2] then 82 if arg[2] then
83 -- prosodyctl shell module reload foo bar.com --> module:reload("foo", "bar.com") 83 local fmt = { "%s"; ":%s("; ")" };
84 arg[1] = string.format("%s:%s("..string.rep("%q", #arg-2,", ")..")", unpack(arg)); 84 for i = 3, #arg do
85 if arg[i]:sub(1, 1) == ":" then
86 table.insert(fmt, i, ")%s(");
87 elseif i > 3 and fmt[i - 1] == "%q" then
88 table.insert(fmt, i, ", %q");
89 else
90 table.insert(fmt, i, "%q");
91 end
92 end
93 arg[1] = string.format(table.concat(fmt), table.unpack(arg));
85 end 94 end
86 95
87 client.events.add_handler("connected", function() 96 client.events.add_handler("connected", function()
88 send_line(client, arg[1]); 97 send_line(client, arg[1]);
89 return true; 98 return true;