Skip to content

Commit

Permalink
Remove requires confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Feb 19, 2023
1 parent 745b090 commit 67cb89b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/mrsk/cli/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/cli/accessory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) }
Expand Down

0 comments on commit 67cb89b

Please sign in to comment.