~singpolyma/sgx-jmp

9827b8b48336d249637f88d6921d613ad12b16f1 — Stephen Paul Weber 5 months ago c92ea39
Allow finishing adming command
1 files changed, 8 insertions(+), 6 deletions(-)

M lib/admin_command.rb
M lib/admin_command.rb => lib/admin_command.rb +8 -6
@@ 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)