#N/A Add docker_not_command rule

This commit is contained in:
nvbn
2015-07-24 00:12:29 +03:00
parent b5f2d0afb5
commit f9f0948349
3 changed files with 158 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
from itertools import dropwhile, takewhile, islice
import re
import subprocess
from thefuck.utils import get_closest, sudo_support
@sudo_support
def match(command, settings):
return command.script.startswith('docker') \
and 'is not a docker command' in command.stderr
def get_docker_commands():
proc = subprocess.Popen('docker', stdout=subprocess.PIPE)
lines = [line.decode('utf-8') for line in proc.stdout.readlines()]
lines = dropwhile(lambda line: not line.startswith('Commands:'), lines)
lines = islice(lines, 1, None)
lines = list(takewhile(lambda line: line != '\n', lines))
return [line.strip().split(' ')[0] for line in lines]
@sudo_support
def get_new_command(command, settings):
wrong_command = re.findall(
r"docker: '(\w+)' is not a docker command.", command.stderr)[0]
fixed_command = get_closest(wrong_command, get_docker_commands())
return command.script.replace(
' {}'.format(wrong_command), ' {}'.format(fixed_command), 1)