1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 14:48:49 +00:00

remove container before deleting image

This commit is contained in:
Connor Martin 2019-07-05 14:43:21 -05:00
parent dac27923bd
commit 37546b9c37
2 changed files with 14 additions and 10 deletions

View File

@ -3,13 +3,15 @@ from thefuck.types import Command
def test_match():
err_response = """
Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image
is being used by running container e5e2591040d1
"""
err_response = """Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image is being used by running container e5e2591040d1"""
assert match(Command('docker image rm -f cd809b04b6ff', err_response))
def test_get_new_command():
assert get_new_command(Command('docker image rm -f cd809b04b6ff',
'')) == 'docker container rm -f e5e2591040d1 && docker image rm -f cd809b04b6ff'
err_response = """
Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image
is being used by running container e5e2591040d1
"""
result = get_new_command(Command('docker image rm -f cd809b04b6ff', err_response))
expected = 'docker container rm -f e5e2591040d1 && docker image rm -f cd809b04b6ff'
assert result == expected

View File

@ -1,11 +1,13 @@
from thefuck.utils import for_app, replace_command
from thefuck.utils import for_app
@for_app('docker')
def match(command):
return 'image is being used by running container' in command.output
return ('docker' in command.script
and 'image is being used by running container' in command.output)
def get_new_command(command):
container_id = command.output.split(' ')[-1]
return 'docker container rm -f {} && {}'.format(container_id, command.script)
container_id = command.output.strip().split(' ')
print(container_id[-1])
return 'docker container rm -f {} && {}'.format(container_id[-1], command.script)