From b617c24af4e1cc79fd27ed3dc852d6b9e53be543 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Mar 2022 10:21:43 +0000 Subject: util.prosodyctl.shell: Support for receiving partial lines (no automatic \n) --- util/prosodyctl/shell.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'util/prosodyctl') diff --git a/util/prosodyctl/shell.lua b/util/prosodyctl/shell.lua index bce27b94..0b1dd3f9 100644 --- a/util/prosodyctl/shell.lua +++ b/util/prosodyctl/shell.lua @@ -89,11 +89,15 @@ local function start(arg) --luacheck: ignore 212/arg 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 + local dest = io.stdout; if stanza.attr.type == "error" then errors = errors + 1; - io.stderr:write(stanza:get_text(), "\n"); + dest = io.stderr; + end + if stanza.attr.eol == "0" then + dest:write(stanza:get_text()); else - print(stanza:get_text()); + dest:write(stanza:get_text(), "\n"); end end if stanza.name == "repl-result" then -- cgit v1.2.3 From 0267554c8e91555c658241861943b684e5f98000 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 30 May 2022 15:28:44 +0200 Subject: prosodyctl shell: Communicate width of terminal to mod_admin_shell This lets it adjust the width of tables to the actual terminal width. --- util/prosodyctl/shell.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/prosodyctl') diff --git a/util/prosodyctl/shell.lua b/util/prosodyctl/shell.lua index 0b1dd3f9..cad9ac00 100644 --- a/util/prosodyctl/shell.lua +++ b/util/prosodyctl/shell.lua @@ -27,7 +27,7 @@ local function read_line(prompt_string) end local function send_line(client, line) - client.send(st.stanza("repl-input"):text(line)); + client.send(st.stanza("repl-input", { width = os.getenv "COLUMNS" }):text(line)); end local function repl(client) -- cgit v1.2.3 From 02f67bb9171552b69088c77c3d722a53b83e8650 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Jun 2022 13:59:00 +0200 Subject: util.prosodyctl.shell: Print errors in red to highlight them --- util/prosodyctl/shell.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'util/prosodyctl') diff --git a/util/prosodyctl/shell.lua b/util/prosodyctl/shell.lua index cad9ac00..8f910301 100644 --- a/util/prosodyctl/shell.lua +++ b/util/prosodyctl/shell.lua @@ -4,6 +4,8 @@ local st = require "util.stanza"; local path = require "util.paths"; local parse_args = require "util.argparse".parse; local unpack = table.unpack or _G.unpack; +local tc = require "util.termcolours"; +local isatty = require "util.pposix".isatty; local have_readline, readline = pcall(require, "readline"); @@ -64,6 +66,7 @@ end local function start(arg) --luacheck: ignore 212/arg local client = adminstream.client(); local opts, err, where = parse_args(arg); + local ttyout = isatty(io.stdout); if not opts then if err == "param-not-found" then @@ -122,7 +125,11 @@ local function start(arg) --luacheck: ignore 212/arg client.events.add_handler("received", function (stanza) if stanza.name == "repl-output" or stanza.name == "repl-result" then local result_prefix = stanza.attr.type == "error" and "!" or "|"; - print(result_prefix.." "..stanza:get_text()); + local out = result_prefix.." "..stanza:get_text(); + if ttyout and stanza.attr.type == "error" then + out = tc.getstring(tc.getstyle("red"), out); + end + print(out); end if stanza.name == "repl-result" then repl(client); -- cgit v1.2.3 From 49a9a1e76a34d67cfa2be24cbb2e2a9db545f969 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 2 Jul 2022 17:31:14 +0200 Subject: util: Remove various Lua 5.1 compatibility hacks Part of #1600 --- util/prosodyctl/shell.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'util/prosodyctl') diff --git a/util/prosodyctl/shell.lua b/util/prosodyctl/shell.lua index 8f910301..5f99bec1 100644 --- a/util/prosodyctl/shell.lua +++ b/util/prosodyctl/shell.lua @@ -80,8 +80,7 @@ local function start(arg) --luacheck: ignore 212/arg if arg[1] then if arg[2] then -- prosodyctl shell module reload foo bar.com --> module:reload("foo", "bar.com") - -- COMPAT Lua 5.1 doesn't have the separator argument to string.rep - arg[1] = string.format("%s:%s("..string.rep("%q, ", #arg-2):sub(1, -3)..")", unpack(arg)); + arg[1] = string.format("%s:%s("..string.rep("%q", #arg-2,", ")..")", unpack(arg)); end client.events.add_handler("connected", function() -- cgit v1.2.3 From bfa6d5634afbed156537de9eb620964b24111ff2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 6 Oct 2022 11:12:57 +0100 Subject: prosodyctl: check turn: More clearly indicate the error is from TURN server --- util/prosodyctl/check.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/prosodyctl') diff --git a/util/prosodyctl/check.lua b/util/prosodyctl/check.lua index 42d73f29..3f89f930 100644 --- a/util/prosodyctl/check.lua +++ b/util/prosodyctl/check.lua @@ -155,7 +155,7 @@ local function check_turn_service(turn_service, ping_service) result.error = "TURN server did not response to allocation request: "..err; return result; elseif alloc_response:is_err_resp() then - result.error = ("TURN allocation failed: %d (%s)"):format(alloc_response:get_error()); + result.error = ("TURN server failed to create allocation: %d (%s)"):format(alloc_response:get_error()); return result; elseif not alloc_response:is_success_resp() then result.error = ("Unexpected TURN response: %d (%s)"):format(alloc_response:get_type()); -- cgit v1.2.3 From 03814250c300b8cbaaccfde6bdb856039c3a4691 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 20 Oct 2022 17:37:33 +0200 Subject: util.prosodyctl.cert: Remove Lua 5.1 os.execute() return value compat --- util/prosodyctl/cert.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/prosodyctl') diff --git a/util/prosodyctl/cert.lua b/util/prosodyctl/cert.lua index 02c81585..ebc14a4e 100644 --- a/util/prosodyctl/cert.lua +++ b/util/prosodyctl/cert.lua @@ -179,7 +179,7 @@ local function copy(from, to, umask, owner, group) os.execute(("chown -c --reference=%s %s"):format(sh_esc(cert_basedir), sh_esc(to))); elseif owner and group then local ok = os.execute(("chown %s:%s %s"):format(sh_esc(owner), sh_esc(group), sh_esc(to))); - assert(ok == true or ok == 0, "Failed to change ownership of "..to); + assert(ok, "Failed to change ownership of "..to); end if old_umask then pposix.umask(old_umask); end return true; -- cgit v1.2.3