From 67cb89b9b920eea929be90b791e4658ba4436003 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 19 Feb 2023 16:30:00 +0100 Subject: [PATCH] Remove requires confirmation --- lib/mrsk/cli/accessory.rb | 16 ++++++++++------ test/cli/accessory_test.rb | 8 ++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/mrsk/cli/accessory.rb b/lib/mrsk/cli/accessory.rb index b658609c9..309e23810 100644 --- a/lib/mrsk/cli/accessory.rb +++ b/lib/mrsk/cli/accessory.rb @@ -153,13 +153,17 @@ def logs(name) option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question" def remove(name) if name == "all" - MRSK.accessory_names.each { |accessory_name| remove(accessory_name) } + if options[:confirmed] || ask("This will remove all containers and images for all accessories. Are you sure?", limited_to: %w( y N ), default: "N") == "y" + MRSK.accessory_names.each { |accessory_name| remove(accessory_name) } + end else - with_accessory(name) do - stop(name) - remove_container(name) - remove_image(name) - remove_service_directory(name) + if options[:confirmed] || ask("This will remove all containers and images for #{name}. Are you sure?", limited_to: %w( y N ), default: "N") == "y" + with_accessory(name) do + stop(name) + remove_container(name) + remove_image(name) + remove_service_directory(name) + end end end end diff --git a/test/cli/accessory_test.rb b/test/cli/accessory_test.rb index 9a74deed9..c9d577b61 100644 --- a/test/cli/accessory_test.rb +++ b/test/cli/accessory_test.rb @@ -31,6 +31,14 @@ class CliAccessoryTest < CliTestCase end end + test "remove with confirmation" do + run_command("remove", "mysql", "-y").tap do |output| + assert_match /docker container stop app-mysql/, output + assert_match /docker image prune -a -f --filter label=service=app-mysql/, output + assert_match /rm -rf app-mysql/, output + end + end + private def run_command(*command) stdouted { Mrsk::Cli::Accessory.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }