Comparison

util/prosodyctl/shell.lua @ 11423:0a10bb3b129b

util.prosodyctl.shell: Allow passing a single command as argument Test procedure: $ prosodyctl shell 'server:version()' Expect: > OK: hg:926d53af9a7a $ prosodyctl shell 'server:version()' 'hello' Expect: > Only one command is supported as argument $ prosodyctl shell 'lorem ipsum'; echo $? Expect: > Sorry, I couldn't understand that... console:1: syntax error near 'show' > 1 (error code) Thanks Menel for mentioning the feature
author Kim Alvefur <zash@zash.se>
date Fri, 05 Mar 2021 13:02:37 +0100
parent 11422:fa5a23d7aabc
child 11520:0a464a6e88c4
comparison
equal deleted inserted replaced
11422:fa5a23d7aabc 11423:0a10bb3b129b
69 print("Expected a value to follow command-line option: "..where); 69 print("Expected a value to follow command-line option: "..where);
70 end 70 end
71 os.exit(1); 71 os.exit(1);
72 end 72 end
73 73
74 if arg[1] then
75 if arg[2] then
76 -- TODO send each arg[] and wait for reply?
77 print("Only one command is supported as argument");
78 os.exit(1);
79 end
80
81 client.events.add_handler("connected", function()
82 client.send(st.stanza("repl-input"):text(arg[1]));
83 return true;
84 end, 1);
85
86 local errors = 0; -- TODO This is weird, but works for now.
87 client.events.add_handler("received", function(stanza)
88 if stanza.name == "repl-output" or stanza.name == "repl-result" then
89 if stanza.attr.type == "error" then
90 errors = errors + 1;
91 io.stderr:write(stanza:get_text(), "\n");
92 else
93 print(stanza:get_text());
94 end
95 end
96 if stanza.name == "repl-result" then
97 os.exit(errors);
98 end
99 return true;
100 end, 1);
101 end
102
74 client.events.add_handler("connected", function () 103 client.events.add_handler("connected", function ()
75 if not opts.quiet then 104 if not opts.quiet then
76 printbanner(); 105 printbanner();
77 end 106 end
78 repl(client); 107 repl(client);