# HG changeset patch # User Kim Alvefur # Date 1614945757 -3600 # Node ID 0a10bb3b129bfc0f54861083b272238e5cd12ac5 # Parent fa5a23d7aabc6aa37d3af5db4276f71b3fe08d5b 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 diff -r fa5a23d7aabc -r 0a10bb3b129b util/prosodyctl/shell.lua --- a/util/prosodyctl/shell.lua Fri Mar 05 12:39:49 2021 +0100 +++ b/util/prosodyctl/shell.lua Fri Mar 05 13:02:37 2021 +0100 @@ -71,6 +71,35 @@ os.exit(1); end + 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); + end + + client.events.add_handler("connected", function() + client.send(st.stanza("repl-input"):text(arg[1])); + return true; + end, 1); + + local errors = 0; -- TODO This is weird, but works for now. + client.events.add_handler("received", function(stanza) + if stanza.name == "repl-output" or stanza.name == "repl-result" then + if stanza.attr.type == "error" then + errors = errors + 1; + io.stderr:write(stanza:get_text(), "\n"); + else + print(stanza:get_text()); + end + end + if stanza.name == "repl-result" then + os.exit(errors); + end + return true; + end, 1); + end + client.events.add_handler("connected", function () if not opts.quiet then printbanner();