From b7fc483ca46438162e85e163bc57427081edde74 Mon Sep 17 00:00:00 2001 From: DashBing Date: Mon, 21 Aug 2023 10:55:29 +0800 Subject: [PATCH] fix many files in rules/ --- thefuck/rules/git_pull_uncommitted_changes.py | 10 +++++-- thefuck/rules/git_push.py | 12 +++++--- thefuck/rules/git_push_force.py | 6 ++-- thefuck/rules/git_push_pull.py | 26 +++++++++++------ thefuck/rules/git_rebase_merge_dir.py | 8 +++-- thefuck/rules/git_remote_seturl_add.py | 6 ++-- thefuck/rules/git_rm_local_modifications.py | 8 +++-- thefuck/rules/git_rm_recursive.py | 8 +++-- thefuck/rules/git_rm_staged.py | 8 +++-- thefuck/rules/git_stash_pop.py | 8 +++-- thefuck/rules/git_tag_force.py | 6 ++-- thefuck/rules/git_two_dashes.py | 6 ++-- thefuck/rules/go_run.py | 6 ++-- thefuck/rules/go_unknown_command.py | 6 ++-- thefuck/rules/gradle_wrapper.py | 8 +++-- thefuck/rules/grunt_task_not_found.py | 6 ++-- thefuck/rules/gulp_not_task.py | 18 ++++++++---- thefuck/rules/history.py | 14 ++++++--- thefuck/rules/hostscli.py | 3 +- thefuck/rules/lein_not_task.py | 12 +++++--- thefuck/rules/ln_no_hard_link.py | 6 ++-- thefuck/rules/ln_s_order.py | 6 ++-- thefuck/rules/man_no_space.py | 6 ++-- thefuck/rules/mercurial.py | 6 ++-- .../rules/missing_space_before_subcommand.py | 6 ++-- thefuck/rules/mkdir_p.py | 6 ++-- thefuck/rules/mvn_no_command.py | 6 ++-- thefuck/rules/mvn_unknown_lifecycle_phase.py | 9 ++++-- thefuck/rules/no_command.py | 29 +++++++++++++------ 29 files changed, 176 insertions(+), 89 deletions(-) diff --git a/thefuck/rules/git_pull_uncommitted_changes.py b/thefuck/rules/git_pull_uncommitted_changes.py index 152503c..c9d8954 100644 --- a/thefuck/rules/git_pull_uncommitted_changes.py +++ b/thefuck/rules/git_pull_uncommitted_changes.py @@ -4,9 +4,13 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('pull' in command.script - and ('You have unstaged changes' in command.output - or 'contains uncommitted changes' in command.output)) + return ( + 'pull' in command.script + and ( + 'You have unstaged changes' in command.output + or 'contains uncommitted changes' in command.output + ) + ) @git_support diff --git a/thefuck/rules/git_push.py b/thefuck/rules/git_push.py index 018ff15..d339c3e 100644 --- a/thefuck/rules/git_push.py +++ b/thefuck/rules/git_push.py @@ -5,8 +5,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('push' in command.script_parts - and 'git push --set-upstream' in command.output) + return ( + 'push' in command.script_parts + and 'git push --set-upstream' in command.output + ) def _get_upstream_option_index(command_parts): @@ -40,5 +42,7 @@ def get_new_command(command): command_parts.pop(len(command_parts) - 1) arguments = re.findall(r'git push (.*)', command.output)[-1].replace("'", r"\'").strip() - return replace_argument(" ".join(command_parts), 'push', - 'push {}'.format(arguments)) + return replace_argument( + " ".join(command_parts), 'push', + 'push {}'.format(arguments) + ) diff --git a/thefuck/rules/git_push_force.py b/thefuck/rules/git_push_force.py index 45c56ec..f9a8b59 100644 --- a/thefuck/rules/git_push_force.py +++ b/thefuck/rules/git_push_force.py @@ -4,10 +4,12 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('push' in command.script + return ( + 'push' in command.script and '! [rejected]' in command.output and 'failed to push some refs to' in command.output - and 'Updates were rejected because the tip of your current branch is behind' in command.output) + and 'Updates were rejected because the tip of your current branch is behind' in command.output + ) @git_support diff --git a/thefuck/rules/git_push_pull.py b/thefuck/rules/git_push_pull.py index 59ab1d5..3539b60 100644 --- a/thefuck/rules/git_push_pull.py +++ b/thefuck/rules/git_push_pull.py @@ -5,16 +5,24 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('push' in command.script and - '! [rejected]' in command.output and - 'failed to push some refs to' in command.output and - ('Updates were rejected because the tip of your' - ' current branch is behind' in command.output or - 'Updates were rejected because the remote ' - 'contains work that you do' in command.output)) + return ( + 'push' in command.script and + '! [rejected]' in command.output and + 'failed to push some refs to' in command.output and ( + ( + 'Updates were rejected because the tip of your' + ' current branch is behind' in command.output + ) or ( + 'Updates were rejected because the remote ' + 'contains work that you do' in command.output + ) + ) + ) @git_support def get_new_command(command): - return shell.and_(replace_argument(command.script, 'push', 'pull'), - command.script) + return shell.and_( + replace_argument(command.script, 'push', 'pull'), + command.script + ) diff --git a/thefuck/rules/git_rebase_merge_dir.py b/thefuck/rules/git_rebase_merge_dir.py index 8251dd1..3bc3982 100644 --- a/thefuck/rules/git_rebase_merge_dir.py +++ b/thefuck/rules/git_rebase_merge_dir.py @@ -4,9 +4,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' rebase' in command.script and - 'It seems that there is already a rebase-merge directory' in command.output and - 'I wonder if you are in the middle of another rebase' in command.output) + return ( + ' rebase' in command.script and + 'It seems that there is already a rebase-merge directory' in command.output and + 'I wonder if you are in the middle of another rebase' in command.output + ) @git_support diff --git a/thefuck/rules/git_remote_seturl_add.py b/thefuck/rules/git_remote_seturl_add.py index 39fcc93..ddda988 100644 --- a/thefuck/rules/git_remote_seturl_add.py +++ b/thefuck/rules/git_remote_seturl_add.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('set-url' in command.script - and 'fatal: No such remote' in command.output) + return ( + 'set-url' in command.script + and 'fatal: No such remote' in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/git_rm_local_modifications.py b/thefuck/rules/git_rm_local_modifications.py index 602fb30..6c8b4f2 100644 --- a/thefuck/rules/git_rm_local_modifications.py +++ b/thefuck/rules/git_rm_local_modifications.py @@ -3,9 +3,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' rm ' in command.script and - 'error: the following file has local modifications' in command.output and - 'use --cached to keep the file, or -f to force removal' in command.output) + return ( + ' rm ' in command.script and + 'error: the following file has local modifications' in command.output and + 'use --cached to keep the file, or -f to force removal' in command.output + ) @git_support diff --git a/thefuck/rules/git_rm_recursive.py b/thefuck/rules/git_rm_recursive.py index 5870e25..0618ac2 100644 --- a/thefuck/rules/git_rm_recursive.py +++ b/thefuck/rules/git_rm_recursive.py @@ -3,9 +3,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' rm ' in command.script - and "fatal: not removing '" in command.output - and "' recursively without -r" in command.output) + return ( + ' rm ' in command.script + and "fatal: not removing '" in command.output + and "' recursively without -r" in command.output + ) @git_support diff --git a/thefuck/rules/git_rm_staged.py b/thefuck/rules/git_rm_staged.py index 1f8e585..7816625 100644 --- a/thefuck/rules/git_rm_staged.py +++ b/thefuck/rules/git_rm_staged.py @@ -3,9 +3,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' rm ' in command.script and - 'error: the following file has changes staged in the index' in command.output and - 'use --cached to keep the file, or -f to force removal' in command.output) + return ( + ' rm ' in command.script and + 'error: the following file has changes staged in the index' in command.output and + 'use --cached to keep the file, or -f to force removal' in command.output + ) @git_support diff --git a/thefuck/rules/git_stash_pop.py b/thefuck/rules/git_stash_pop.py index 0e143ff..a14fa4f 100644 --- a/thefuck/rules/git_stash_pop.py +++ b/thefuck/rules/git_stash_pop.py @@ -4,9 +4,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('stash' in command.script - and 'pop' in command.script - and 'Your local changes to the following files would be overwritten by merge' in command.output) + return ( + 'stash' in command.script + and 'pop' in command.script + and 'Your local changes to the following files would be overwritten by merge' in command.output + ) @git_support diff --git a/thefuck/rules/git_tag_force.py b/thefuck/rules/git_tag_force.py index 63e8e39..23d20b0 100644 --- a/thefuck/rules/git_tag_force.py +++ b/thefuck/rules/git_tag_force.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('tag' in command.script_parts - and 'already exists' in command.output) + return ( + 'tag' in command.script_parts + and 'already exists' in command.output + ) @git_support diff --git a/thefuck/rules/git_two_dashes.py b/thefuck/rules/git_two_dashes.py index 3569dca..3a6f120 100644 --- a/thefuck/rules/git_two_dashes.py +++ b/thefuck/rules/git_two_dashes.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('error: did you mean `' in command.output - and '` (with two dashes ?)' in command.output) + return ( + 'error: did you mean `' in command.output + and '` (with two dashes ?)' in command.output + ) @git_support diff --git a/thefuck/rules/go_run.py b/thefuck/rules/go_run.py index 30db699..f5b23ab 100644 --- a/thefuck/rules/go_run.py +++ b/thefuck/rules/go_run.py @@ -8,8 +8,10 @@ from thefuck.utils import for_app @for_app('go') def match(command): - return (command.script.startswith('go run ') - and not command.script.endswith('.go')) + return ( + command.script.startswith('go run ') + and not command.script.endswith('.go') + ) def get_new_command(command): diff --git a/thefuck/rules/go_unknown_command.py b/thefuck/rules/go_unknown_command.py index 20d5242..4859c00 100644 --- a/thefuck/rules/go_unknown_command.py +++ b/thefuck/rules/go_unknown_command.py @@ -24,5 +24,7 @@ def match(command): def get_new_command(command): closest_subcommand = get_closest(command.script_parts[1], get_golang_commands()) - return replace_argument(command.script, command.script_parts[1], - closest_subcommand) + return replace_argument( + command.script, command.script_parts[1], + closest_subcommand + ) diff --git a/thefuck/rules/gradle_wrapper.py b/thefuck/rules/gradle_wrapper.py index 94b750c..1894350 100644 --- a/thefuck/rules/gradle_wrapper.py +++ b/thefuck/rules/gradle_wrapper.py @@ -4,9 +4,11 @@ from thefuck.utils import for_app, which @for_app('gradle') def match(command): - return (not which(command.script_parts[0]) - and 'not found' in command.output - and os.path.isfile('gradlew')) + return ( + not which(command.script_parts[0]) + and 'not found' in command.output + and os.path.isfile('gradlew') + ) def get_new_command(command): diff --git a/thefuck/rules/grunt_task_not_found.py b/thefuck/rules/grunt_task_not_found.py index 49bf0b4..b6284dd 100644 --- a/thefuck/rules/grunt_task_not_found.py +++ b/thefuck/rules/grunt_task_not_found.py @@ -33,5 +33,7 @@ def get_new_command(command): misspelled_task = regex.findall(command.output)[0].split(':')[0] tasks = _get_all_tasks() fixed = get_closest(misspelled_task, tasks) - return command.script.replace(' {}'.format(misspelled_task), - ' {}'.format(fixed)) + return command.script.replace( + ' {}'.format(misspelled_task), + ' {}'.format(fixed) + ) diff --git a/thefuck/rules/gulp_not_task.py b/thefuck/rules/gulp_not_task.py index e0d8589..b224731 100644 --- a/thefuck/rules/gulp_not_task.py +++ b/thefuck/rules/gulp_not_task.py @@ -10,13 +10,19 @@ def match(command): @cache('gulpfile.js') def get_gulp_tasks(): - proc = subprocess.Popen(['gulp', '--tasks-simple'], - stdout=subprocess.PIPE) - return [line.decode('utf-8')[:-1] - for line in proc.stdout.readlines()] + proc = subprocess.Popen( + ['gulp', '--tasks-simple'], + stdout=subprocess.PIPE + ) + return [ + line.decode('utf-8')[:-1] + for line in proc.stdout.readlines() + ] def get_new_command(command): - wrong_task = re.findall(r"Task '(\w+)' is not in your gulpfile", - command.output)[0] + wrong_task = re.findall( + r"Task '(\w+)' is not in your gulpfile", + command.output + )[0] return replace_command(command, wrong_task, get_gulp_tasks()) diff --git a/thefuck/rules/history.py b/thefuck/rules/history.py index 0ebe548..3a66f12 100644 --- a/thefuck/rules/history.py +++ b/thefuck/rules/history.py @@ -3,13 +3,19 @@ from thefuck.utils import get_close_matches, get_closest, \ def match(command): - return len(get_close_matches(command.script, - get_valid_history_without_current(command))) + return len( + get_close_matches( + command.script, + get_valid_history_without_current(command) + ) + ) def get_new_command(command): - return get_closest(command.script, - get_valid_history_without_current(command)) + return get_closest( + command.script, + get_valid_history_without_current(command) + ) priority = 9999 diff --git a/thefuck/rules/hostscli.py b/thefuck/rules/hostscli.py index debc9ac..6187752 100644 --- a/thefuck/rules/hostscli.py +++ b/thefuck/rules/hostscli.py @@ -22,6 +22,7 @@ def get_new_command(command): return ['hostscli websites'] misspelled_command = re.findall( - r'Error: No such command ".*"', command.output)[0] + r'Error: No such command ".*"', command.output + )[0] commands = ['block', 'unblock', 'websites', 'block_all', 'unblock_all'] return replace_command(command, misspelled_command, commands) diff --git a/thefuck/rules/lein_not_task.py b/thefuck/rules/lein_not_task.py index b960b1a..5265291 100644 --- a/thefuck/rules/lein_not_task.py +++ b/thefuck/rules/lein_not_task.py @@ -6,14 +6,18 @@ from thefuck.specific.sudo import sudo_support @sudo_support @for_app('lein') def match(command): - return (command.script.startswith('lein') + return ( + command.script.startswith('lein') and "is not a task. See 'lein help'" in command.output - and 'Did you mean this?' in command.output) + and 'Did you mean this?' in command.output + ) @sudo_support def get_new_command(command): - broken_cmd = re.findall(r"'([^']*)' is not a task", - command.output)[0] + broken_cmd = re.findall( + r"'([^']*)' is not a task", + command.output + )[0] new_cmds = get_all_matched_commands(command.output, 'Did you mean this?') return replace_command(command, broken_cmd, new_cmds) diff --git a/thefuck/rules/ln_no_hard_link.py b/thefuck/rules/ln_no_hard_link.py index 68766d3..b870528 100644 --- a/thefuck/rules/ln_no_hard_link.py +++ b/thefuck/rules/ln_no_hard_link.py @@ -14,8 +14,10 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return (command.output.endswith("hard link not allowed for directory") and - command.script_parts[0] == 'ln') + return ( + command.output.endswith("hard link not allowed for directory") + and command.script_parts[0] == 'ln' + ) @sudo_support diff --git a/thefuck/rules/ln_s_order.py b/thefuck/rules/ln_s_order.py index 963a442..58c9ad2 100644 --- a/thefuck/rules/ln_s_order.py +++ b/thefuck/rules/ln_s_order.py @@ -11,10 +11,12 @@ def _get_destination(script_parts): @sudo_support def match(command): - return (command.script_parts[0] == 'ln' + return ( + command.script_parts[0] == 'ln' and {'-s', '--symbolic'}.intersection(command.script_parts) and 'File exists' in command.output - and _get_destination(command.script_parts)) + and _get_destination(command.script_parts) + ) @sudo_support diff --git a/thefuck/rules/man_no_space.py b/thefuck/rules/man_no_space.py index 86e7716..bde4226 100644 --- a/thefuck/rules/man_no_space.py +++ b/thefuck/rules/man_no_space.py @@ -1,6 +1,8 @@ def match(command): - return (command.script.startswith(u'man') - and u'command not found' in command.output.lower()) + return ( + command.script.startswith(u'man') + and u'command not found' in command.output.lower() + ) def get_new_command(command): diff --git a/thefuck/rules/mercurial.py b/thefuck/rules/mercurial.py index ae6f7aa..f11d048 100644 --- a/thefuck/rules/mercurial.py +++ b/thefuck/rules/mercurial.py @@ -14,10 +14,12 @@ def extract_possibilities(command): @for_app('hg') def match(command): - return ('hg: unknown command' in command.output + return ( + 'hg: unknown command' in command.output and '(did you mean one of ' in command.output or "hg: command '" in command.output - and "' is ambiguous:" in command.output) + and "' is ambiguous:" in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/missing_space_before_subcommand.py b/thefuck/rules/missing_space_before_subcommand.py index fd4fbd7..932fa5d 100644 --- a/thefuck/rules/missing_space_before_subcommand.py +++ b/thefuck/rules/missing_space_before_subcommand.py @@ -9,8 +9,10 @@ def _get_executable(script_part): def match(command): - return (not command.script_parts[0] in get_all_executables() - and _get_executable(command.script_parts[0])) + return ( + not command.script_parts[0] in get_all_executables() + and _get_executable(command.script_parts[0]) + ) def get_new_command(command): diff --git a/thefuck/rules/mkdir_p.py b/thefuck/rules/mkdir_p.py index 3f781e1..66a81b0 100644 --- a/thefuck/rules/mkdir_p.py +++ b/thefuck/rules/mkdir_p.py @@ -4,8 +4,10 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return ('mkdir' in command.script - and 'No such file or directory' in command.output) + return ( + 'mkdir' in command.script + and 'No such file or directory' in command.output + ) @sudo_support diff --git a/thefuck/rules/mvn_no_command.py b/thefuck/rules/mvn_no_command.py index 36c2a0a..425ffe0 100644 --- a/thefuck/rules/mvn_no_command.py +++ b/thefuck/rules/mvn_no_command.py @@ -7,5 +7,7 @@ def match(command): def get_new_command(command): - 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 fa2cf20..6c02bcc 100644 --- a/thefuck/rules/mvn_unknown_lifecycle_phase.py +++ b/thefuck/rules/mvn_unknown_lifecycle_phase.py @@ -3,13 +3,16 @@ import re def _get_failed_lifecycle(command): - return re.search(r'\[ERROR\] Unknown lifecycle phase "(.+)"', - command.output) + return re.search( + r'\[ERROR\] Unknown lifecycle phase "(.+)"', + command.output + ) def _getavailable_lifecycles(command): return re.search( - r'Available lifecycle phases are: (.+) -> \[Help 1\]', command.output) + r'Available lifecycle phases are: (.+) -> \[Help 1\]', command.output + ) @for_app('mvn') diff --git a/thefuck/rules/no_command.py b/thefuck/rules/no_command.py index 0862329..052d262 100644 --- a/thefuck/rules/no_command.py +++ b/thefuck/rules/no_command.py @@ -5,11 +5,17 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return (not which(command.script_parts[0]) - and ('not found' in command.output - or 'is not recognized as' in command.output) - and bool(get_close_matches(command.script_parts[0], - get_all_executables()))) + return ( + not which(command.script_parts[0]) + and ('not found' in command.output + or 'is not recognized as' in command.output) + and bool( + get_close_matches( + command.script_parts[0], + get_all_executables() + ) + ) + ) def _get_used_executables(command): @@ -24,16 +30,21 @@ def get_new_command(command): # One from history: already_used = get_closest( old_command, _get_used_executables(command), - fallback_to_first=False) + fallback_to_first=False + ) if already_used: new_cmds = [already_used] else: new_cmds = [] # Other from all executables: - new_cmds += [cmd for cmd in get_close_matches(old_command, - get_all_executables()) - if cmd not in new_cmds] + new_cmds += [ + cmd for cmd in get_close_matches( + old_command, + get_all_executables() + ) + if cmd not in new_cmds + ] return [command.script.replace(old_command, cmd, 1) for cmd in new_cmds]