1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-06 02:41:10 +01:00

#351 Speed-up mvn rules, pep8 fixes

This commit is contained in:
nvbn 2015-08-27 16:10:50 +03:00
parent 9103c1ffd5
commit f2a7364e8c
3 changed files with 30 additions and 14 deletions

View File

@ -1,8 +1,11 @@
from thefuck import shells
from thefuck.utils import for_app
@for_app('mvn')
def match(command, settings):
return 'No goals have been specified for this build' in command.stdout and command.script.startswith('mvn')
return 'No goals have been specified for this build' in command.stdout
def get_new_command(command, settings):
return [ command.script + ' clean package', command.script + ' clean install']
return [command.script + ' clean package',
command.script + ' clean install']

View File

@ -1,20 +1,32 @@
from thefuck import shells
from thefuck.utils import replace_command
from thefuck.utils import replace_command, for_app
from difflib import get_close_matches
import re
def _get_failed_lifecycle(command):
return re.search(r'\[ERROR\] Unknown lifecycle phase "(.+)"',
command.stdout)
def _getavailable_lifecycles(command):
return re.search(
r'Available lifecycle phases are: (.+) -> \[Help 1\]', command.stdout)
@for_app('mvn')
def match(command, settings):
failedLifecycle = re.search('\[ERROR\] Unknown lifecycle phase "(.+)"', command.stdout)
availableLifecycles = re.search('Available lifecycle phases are: (.+) -> \[Help 1\]', command.stdout)
return availableLifecycles and failedLifecycle and command.script.startswith('mvn')
failed_lifecycle = _get_failed_lifecycle(command)
available_lifecycles = _getavailable_lifecycles(command)
return available_lifecycles and failed_lifecycle
def get_new_command(command, settings):
failedLifecycle = re.search('\[ERROR\] Unknown lifecycle phase "(.+)"', command.stdout)
availableLifecycles = re.search('Available lifecycle phases are: (.+) -> \[Help 1\]', command.stdout)
if availableLifecycles and failedLifecycle:
selectedLifecycle = get_close_matches(failedLifecycle.group(1), availableLifecycles.group(1).split(", "), 3, 0.6)
return replace_command(command, failedLifecycle.group(1), selectedLifecycle)
failed_lifecycle = _get_failed_lifecycle(command)
available_lifecycles = _getavailable_lifecycles(command)
if available_lifecycles and failed_lifecycle:
selected_lifecycle = get_close_matches(
failed_lifecycle.group(1), available_lifecycles.group(1).split(", "),
3, 0.6)
return replace_command(command, failed_lifecycle.group(1), selected_lifecycle)
else:
return []

View File

@ -138,7 +138,8 @@ def replace_command(command, broken, matched):
def is_app(command, *app_names):
"""Returns `True` if command is call to one of passed app names."""
for name in app_names:
if command.script.startswith(u'{} '.format(name)):
if command.script == name \
or command.script.startswith(u'{} '.format(name)):
return True
return False