From da30c371e56b8bb577897f1151b59c24e209127f Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 18 Apr 2022 13:44:19 -0500 Subject: [PATCH] Allow finishing admin command --- lib/admin_command.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/admin_command.rb b/lib/admin_command.rb index 0b8e028..c408998 100644 --- a/lib/admin_command.rb +++ b/lib/admin_command.rb @@ -11,30 +11,32 @@ class AdminCommand end def start - action_info.then { menu } + action_info.then { menu_or_done } end def reply(form) Command.reply { |reply| - reply.allowed_actions = [:next] + reply.allowed_actions = [:next, :complete] reply.command << form } end - def menu + def menu_or_done(command_action=:execute) + return Command.finish("Done") if command_action == :complete + reply(FormTemplate.render("admin_menu")).then do |response| if response.form.field("action") - handle(response.form.field("action").value) + handle(response.form.field("action").value, response.action) end end end - def handle(action) + def handle(action, command_action) if respond_to?("action_#{action}") send("action_#{action}") else new_context(action) - end.then { menu } + end.then { menu_or_done(command_action) } end def new_context(q) -- 2.34.5