mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 12:06:04 +00:00
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
This commit is contained in:
parent
4c3a559124
commit
01a5ba99d0
@ -191,6 +191,7 @@ following rules are enabled by default:
|
||||
* `django_south_merge` – adds `--merge` to inconsistent django south migration;
|
||||
* `docker_login` – executes a `docker login` and repeats the previous command;
|
||||
* `docker_not_command` – fixes wrong docker commands like `docker tags`;
|
||||
* `docker_image_being_used_by_container` ‐ removes the container that is using the image before removing the image;
|
||||
* `dry` – fixes repetitions like `git git push`;
|
||||
* `fab_command_not_found` – fix misspelled fabric commands;
|
||||
* `fix_alt_space` – replaces Alt+Space with Space character;
|
||||
|
27
tests/rules/test_docker_image_being_used_by_container.py
Normal file
27
tests/rules/test_docker_image_being_used_by_container.py
Normal file
@ -0,0 +1,27 @@
|
||||
from thefuck.rules.docker_image_being_used_by_container import match, get_new_command
|
||||
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"""
|
||||
assert match(Command('docker image rm -f cd809b04b6ff', err_response))
|
||||
|
||||
|
||||
def test_not_match():
|
||||
err_response = 'bash: docker: command not found'
|
||||
assert not match(Command('docker image rm -f cd809b04b6ff', err_response))
|
||||
|
||||
|
||||
def test_not_docker_command():
|
||||
err_response = """Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image is being used by running container e5e2591040d1"""
|
||||
assert not match(Command('git image rm -f cd809b04b6ff', err_response))
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
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
|
20
thefuck/rules/docker_image_being_used_by_container.py
Normal file
20
thefuck/rules/docker_image_being_used_by_container.py
Normal file
@ -0,0 +1,20 @@
|
||||
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)
|
Loading…
x
Reference in New Issue
Block a user