Allow finishing adming command

Stephen Paul Weber created

Change summary

lib/admin_command.rb | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

Detailed changes

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)