Mercurial > prosody-hg
comparison util/prosodyctl/shell.lua @ 11890:b9aab1962a2b
util.prosodyctl.shell: Allow setting custom prompt (admin_shell_prompt)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 11 Nov 2021 13:27:28 +0000 |
| parents | 5bd38d9197e1 |
| children | 98fd531594bd |
comparison
equal
deleted
inserted
replaced
| 11889:df76802dc09c | 11890:b9aab1962a2b |
|---|---|
| 15 histfile = path.join(prosody.paths.data, ".shell_history"); | 15 histfile = path.join(prosody.paths.data, ".shell_history"); |
| 16 ignoredups = true; | 16 ignoredups = true; |
| 17 }); | 17 }); |
| 18 end | 18 end |
| 19 | 19 |
| 20 local function read_line() | 20 local function read_line(prompt_string) |
| 21 if have_readline then | 21 if have_readline then |
| 22 return readline.readline("prosody> "); | 22 return readline.readline(prompt_string); |
| 23 else | 23 else |
| 24 io.write("prosody> "); | 24 io.write(prompt_string); |
| 25 return io.read("*line"); | 25 return io.read("*line"); |
| 26 end | 26 end |
| 27 end | 27 end |
| 28 | 28 |
| 29 local function send_line(client, line) | 29 local function send_line(client, line) |
| 30 client.send(st.stanza("repl-input"):text(line)); | 30 client.send(st.stanza("repl-input"):text(line)); |
| 31 end | 31 end |
| 32 | 32 |
| 33 local function repl(client) | 33 local function repl(client) |
| 34 local line = read_line(); | 34 local line = read_line(client.prompt_string or "prosody> "); |
| 35 if not line or line == "quit" or line == "exit" or line == "bye" then | 35 if not line or line == "quit" or line == "exit" or line == "bye" then |
| 36 if not line then | 36 if not line then |
| 37 print(""); | 37 print(""); |
| 38 end | 38 end |
| 39 if have_readline then | 39 if have_readline then |
| 121 if stanza.name == "repl-result" then | 121 if stanza.name == "repl-result" then |
| 122 repl(client); | 122 repl(client); |
| 123 end | 123 end |
| 124 end); | 124 end); |
| 125 | 125 |
| 126 client.prompt_string = config.get("*", "admin_shell_prompt"); | |
| 127 | |
| 126 local socket_path = path.resolve_relative_path(prosody.paths.data, opts.socket or config.get("*", "admin_socket") or "prosody.sock"); | 128 local socket_path = path.resolve_relative_path(prosody.paths.data, opts.socket or config.get("*", "admin_socket") or "prosody.sock"); |
| 127 local conn = adminstream.connection(socket_path, client.listeners); | 129 local conn = adminstream.connection(socket_path, client.listeners); |
| 128 local ok, err = conn:connect(); | 130 local ok, err = conn:connect(); |
| 129 if not ok then | 131 if not ok then |
| 130 if err == "no unix socket support" then | 132 if err == "no unix socket support" then |
