diff --git a/thefuck/rules/mvn_no_command.py b/thefuck/rules/mvn_no_command.py index 53c71060..7113c574 100644 --- a/thefuck/rules/mvn_no_command.py +++ b/thefuck/rules/mvn_no_command.py @@ -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'] diff --git a/thefuck/rules/mvn_unknown_lifecycle_phase.py b/thefuck/rules/mvn_unknown_lifecycle_phase.py index 1dcf1ad1..c4a7ee17 100644 --- a/thefuck/rules/mvn_unknown_lifecycle_phase.py +++ b/thefuck/rules/mvn_unknown_lifecycle_phase.py @@ -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 [] diff --git a/thefuck/utils.py b/thefuck/utils.py index 6091e7f0..2887397e 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -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