1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-04-22 02:25:19 +01:00
thefuck/thefuck/rules/docker_image_being_used_by_container.py
Connor Martin 01a5ba99d0 Docker remove container before remove image (#928)
* add docker container removal

* remove container before deleting image

* update readme

* clean up and add assert not test

* test not docker command

* use shell.and_ correctly
2019-07-10 20:34:20 +02:00

21 lines
631 B
Python

from thefuck.utils import for_app
from thefuck.shells import shell
@for_app('docker')
def match(command):
'''
Matches a command's output with docker's output
warning you that you need to remove a container before removing an image.
'''
return 'image is being used by running container' in command.output
def get_new_command(command):
'''
Prepends docker container rm -f {container ID} to
the previous docker image rm {image ID} command
'''
container_id = command.output.strip().split(' ')
return shell.and_('docker container rm -f {}', '{}').format(container_id[-1], command.script)