diff options
author | Kim Alvefur <zash@zash.se> | 2021-03-05 13:02:37 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-03-05 13:02:37 +0100 |
commit | cd641dca64af1b47fb71235a4915ab7c91b4cf90 (patch) | |
tree | b9f3b14a42be0f8ac70f532db4c6ec2cbfdcd0d2 /util/prosodyctl | |
parent | 71cb57df5191da7962185fba8c0dd5847dfd699c (diff) | |
download | prosody-cd641dca64af1b47fb71235a4915ab7c91b4cf90.tar.gz prosody-cd641dca64af1b47fb71235a4915ab7c91b4cf90.zip |
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
Diffstat (limited to 'util/prosodyctl')
-rw-r--r-- | util/prosodyctl/shell.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/util/prosodyctl/shell.lua b/util/prosodyctl/shell.lua index d6da9dab..a05904f0 100644 --- a/util/prosodyctl/shell.lua +++ b/util/prosodyctl/shell.lua @@ -71,6 +71,35 @@ local function start(arg) --luacheck: ignore 212/arg 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(); |