diff options
author | Matthew Wild <mwild1@gmail.com> | 2025-02-17 19:10:26 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2025-02-17 19:10:26 +0000 |
commit | 75b8824b00c1e1dcc83cf496e91d43ed8c0f613a (patch) | |
tree | 3d85155c09fde529f42ddbf63b9f4c33b7b3bc4d | |
parent | efc31d66ef0767e3ceb3e211097841ec31ac18ab (diff) | |
download | prosody-75b8824b00c1e1dcc83cf496e91d43ed8c0f613a.tar.gz prosody-75b8824b00c1e1dcc83cf496e91d43ed8c0f613a.zip |
mod_admin_shell: Fix simple command execution (e.g. help)
-rw-r--r-- | plugins/mod_admin_shell.lua | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua index 7c50b272..ba8067c3 100644 --- a/plugins/mod_admin_shell.lua +++ b/plugins/mod_admin_shell.lua @@ -256,7 +256,7 @@ function console:new_session(admin_session) return session; end -local function process_cmd_line(arg_line) +local function process_cmd_line(session, arg_line) local chunk = load("return "..arg_line, "=shell", "t", {}); local ok, args = pcall(chunk); if not ok then return nil, args; end @@ -268,6 +268,13 @@ local function process_cmd_line(arg_line) local command_help = section_help and section_help.commands[command]; if not command_help then + if commands[section_name] then + commands[section_name](session, table.concat(args, " ")); + return; + end + if section_help then + return nil, "Command not found or necessary module not loaded. Try 'help "..section_name.." for a list of available commands."; + end return nil, "Command not found. Is the necessary module loaded?"; end @@ -390,9 +397,14 @@ local function handle_line(event) if line:match("^{") then -- Input is a serialized array of strings, typically from -- a command-line invocation of 'prosodyctl shell something' - source, flags = process_cmd_line(line); + source, flags = process_cmd_line(session, line); if not source then - send_result(false, flags); + if flags then -- err + send_result(false, flags); + else -- no err, but nothing more to do + -- This happens if it was a "simple" command + event.origin.send(result); + end return; end end |