1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-28 05:28:38 +00:00
thefuck/thefuck/rules/fab_command_not_found.py
2016-08-13 16:14:05 +03:00

38 lines
1.0 KiB
Python

from thefuck.utils import eager, get_closest, for_app
@for_app('fab')
def match(command):
return 'Warning: Command(s) not found:' in command.stderr
# We need different behavior then in get_all_matched_commands.
@eager
def _get_between(content, start, end=None):
should_yield = False
for line in content.split('\n'):
if start in line:
should_yield = True
continue
if end and end in line:
return
if should_yield and line:
yield line.strip().split(' ')[0]
def get_new_command(command):
not_found_commands = _get_between(
command.stderr, 'Warning: Command(s) not found:', 'Available commands:')
possible_commands = _get_between(
command.stdout, 'Available commands:')
script = command.script
for not_found in not_found_commands:
fix = get_closest(not_found, possible_commands)
script = script.replace(' {}'.format(not_found),
' {}'.format(fix))
return script