Software /
code /
prosody
Changeset
13734:c133635d0bc6 13.0
mod_admin_shell: Improved error handling for shell-invoked commands
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 17 Feb 2025 18:25:52 +0000 |
parents | 13733:48c056c10e5a |
children | 13735:5e8a707f1dbf |
files | plugins/mod_admin_shell.lua |
diffstat | 1 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_admin_shell.lua Mon Feb 17 18:24:23 2025 +0000 +++ b/plugins/mod_admin_shell.lua Mon Feb 17 18:25:52 2025 +0000 @@ -265,13 +265,24 @@ local section_mt = getmetatable(def_env[section_name]); local section_help = section_mt and section_mt.help; - local command_help = section_help.commands[command]; + local command_help = section_help and section_help.commands[command]; + + if not command_help then + return nil, "Command not found. Is the necessary module loaded?"; + end local fmt = { "%s"; ":%s("; ")" }; - local flags; if command_help.flags then - flags = parse_args(args, command_help.flags); + local flags, flags_err, flags_err_extra = parse_args(args, command_help.flags); + if not flags then + if flags_err == "missing-value" then + return nil, "Expected value after "..flags_err_extra; + elseif flags_err == "param-not-found" then + return nil, "Unknown parameter: "..flags_err_extra; + end + return nil, flags_err; + end table.remove(flags, 2); table.remove(flags, 1); @@ -380,6 +391,10 @@ -- Input is a serialized array of strings, typically from -- a command-line invocation of 'prosodyctl shell something' source, flags = process_cmd_line(line); + if not source then + send_result(false, flags); + return; + end end local chunkname = "=console"; @@ -2713,8 +2728,13 @@ section_mt.help = section_help; end - if command.flags and command.flags.stop_on_positional == nil then - command.flags.stop_on_positional = false; + if command.flags then + if command.flags.stop_on_positional == nil then + command.flags.stop_on_positional = false; + end + if command.flags.strict == nil then + command.flags.strict = true; + end end section_help.commands[command.name] = {