Mercurial > prosody-hg
comparison util/prosodyctl/shell.lua @ 12539:cfdc8cca64d3
util.prosodyctl.shell: Print errors in red to highlight them
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 01 Jun 2022 13:59:00 +0200 |
| parents | 7dae6d29b71d |
| children | 0f4feaf9ca64 |
comparison
equal
deleted
inserted
replaced
| 12538:0f56587bb37f | 12539:cfdc8cca64d3 |
|---|---|
| 2 local server = require "net.server"; | 2 local server = require "net.server"; |
| 3 local st = require "util.stanza"; | 3 local st = require "util.stanza"; |
| 4 local path = require "util.paths"; | 4 local path = require "util.paths"; |
| 5 local parse_args = require "util.argparse".parse; | 5 local parse_args = require "util.argparse".parse; |
| 6 local unpack = table.unpack or _G.unpack; | 6 local unpack = table.unpack or _G.unpack; |
| 7 local tc = require "util.termcolours"; | |
| 8 local isatty = require "util.pposix".isatty; | |
| 7 | 9 |
| 8 local have_readline, readline = pcall(require, "readline"); | 10 local have_readline, readline = pcall(require, "readline"); |
| 9 | 11 |
| 10 local adminstream = require "util.adminstream"; | 12 local adminstream = require "util.adminstream"; |
| 11 | 13 |
| 62 end | 64 end |
| 63 | 65 |
| 64 local function start(arg) --luacheck: ignore 212/arg | 66 local function start(arg) --luacheck: ignore 212/arg |
| 65 local client = adminstream.client(); | 67 local client = adminstream.client(); |
| 66 local opts, err, where = parse_args(arg); | 68 local opts, err, where = parse_args(arg); |
| 69 local ttyout = isatty(io.stdout); | |
| 67 | 70 |
| 68 if not opts then | 71 if not opts then |
| 69 if err == "param-not-found" then | 72 if err == "param-not-found" then |
| 70 print("Unknown command-line option: "..tostring(where)); | 73 print("Unknown command-line option: "..tostring(where)); |
| 71 elseif err == "missing-value" then | 74 elseif err == "missing-value" then |
| 120 end); | 123 end); |
| 121 | 124 |
| 122 client.events.add_handler("received", function (stanza) | 125 client.events.add_handler("received", function (stanza) |
| 123 if stanza.name == "repl-output" or stanza.name == "repl-result" then | 126 if stanza.name == "repl-output" or stanza.name == "repl-result" then |
| 124 local result_prefix = stanza.attr.type == "error" and "!" or "|"; | 127 local result_prefix = stanza.attr.type == "error" and "!" or "|"; |
| 125 print(result_prefix.." "..stanza:get_text()); | 128 local out = result_prefix.." "..stanza:get_text(); |
| 129 if ttyout and stanza.attr.type == "error" then | |
| 130 out = tc.getstring(tc.getstyle("red"), out); | |
| 131 end | |
| 132 print(out); | |
| 126 end | 133 end |
| 127 if stanza.name == "repl-result" then | 134 if stanza.name == "repl-result" then |
| 128 repl(client); | 135 repl(client); |
| 129 end | 136 end |
| 130 end); | 137 end); |
