fix half of rules/*

This commit is contained in:
DashBing 2023-08-21 10:44:08 +08:00
parent f34bc3d49a
commit 15526bc817
No known key found for this signature in database
GPG Key ID: D6ABB0FFF55D5230
34 changed files with 232 additions and 123 deletions

View File

@ -40,9 +40,11 @@ def _parse_apt_get_and_cache_operations(help_text_lines):
def _get_operations(app):
proc = subprocess.Popen([app, '--help'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc = subprocess.Popen(
[app, '--help'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
lines = proc.stdout.readlines()
if app == 'apt':

View File

@ -12,9 +12,11 @@ def _get_suggestions(str):
@for_app('brew', at_least=2)
def match(command):
is_proper_command = ('install' in command.script and
'No available formula' in command.output and
'Did you mean' in command.output)
is_proper_command = (
'install' in command.script and
'No available formula' in command.output and
'Did you mean' in command.output
)
return is_proper_command

View File

@ -3,8 +3,10 @@ from thefuck.utils import for_app
@for_app('brew', at_least=2)
def match(command):
return (command.script_parts[1] in ['ln', 'link']
and "brew link --overwrite --dry-run" in command.output)
return (
command.script_parts[1] in ['ln', 'link']
and "brew link --overwrite --dry-run" in command.output
)
def get_new_command(command):

View File

@ -2,10 +2,14 @@ import re
from thefuck.utils import for_app
warning_regex = re.compile(r'Warning: (?:.(?!is ))+ is already installed and '
r'up-to-date')
message_regex = re.compile(r'To reinstall (?:(?!, ).)+, run `brew reinstall '
r'[^`]+`')
warning_regex = re.compile(
r'Warning: (?:.(?!is ))+ is already installed and '
r'up-to-date'
)
message_regex = re.compile(
r'To reinstall (?:(?!, ).)+, run `brew reinstall '
r'[^`]+`'
)
@for_app('brew', at_least=2)

View File

@ -3,8 +3,10 @@ from thefuck.utils import for_app
@for_app('brew', at_least=2)
def match(command):
return (command.script_parts[1] in ['uninstall', 'rm', 'remove']
and "brew uninstall --force" in command.output)
return (
command.script_parts[1] in ['uninstall', 'rm', 'remove']
and "brew uninstall --force" in command.output
)
def get_new_command(command):

View File

@ -14,8 +14,10 @@ def _get_brew_commands(brew_path_prefix):
"""To get brew default commands on local environment"""
brew_cmd_path = brew_path_prefix + BREW_CMD_PATH
return [name[:-3] for name in os.listdir(brew_cmd_path)
if name.endswith(('.rb', '.sh'))]
return [
name[:-3] for name in os.listdir(brew_cmd_path)
if name.endswith(('.rb', '.sh'))
]
def _get_brew_tap_specific_commands(brew_path_prefix):
@ -34,9 +36,11 @@ def _get_brew_tap_specific_commands(brew_path_prefix):
tap_cmd_path = brew_taps_path + TAP_CMD_PATH % (user, tap)
if os.path.isdir(tap_cmd_path):
commands += (name.replace('brew-', '').replace('.rb', '')
for name in os.listdir(tap_cmd_path)
if _is_brew_tap_cmd_naming(name))
commands += (
name.replace('brew-', '').replace('.rb', '')
for name in os.listdir(tap_cmd_path)
if _is_brew_tap_cmd_naming(name)
)
return commands
@ -46,23 +50,29 @@ def _is_brew_tap_cmd_naming(name):
def _get_directory_names_only(path):
return [d for d in os.listdir(path)
if os.path.isdir(os.path.join(path, d))]
return [
d for d in os.listdir(path)
if os.path.isdir(os.path.join(path, d))
]
def _brew_commands():
brew_path_prefix = get_brew_path_prefix()
if brew_path_prefix:
try:
return (_get_brew_commands(brew_path_prefix)
+ _get_brew_tap_specific_commands(brew_path_prefix))
return (
_get_brew_commands(brew_path_prefix)
+ _get_brew_tap_specific_commands(brew_path_prefix)
)
except OSError:
pass
# Failback commands for testing (Based on Homebrew 0.9.5)
return ['info', 'home', 'options', 'install', 'uninstall',
'search', 'list', 'update', 'upgrade', 'pin', 'unpin',
'doctor', 'create', 'edit', 'cask']
return [
'info', 'home', 'options', 'install', 'uninstall',
'search', 'list', 'update', 'upgrade', 'pin', 'unpin',
'doctor', 'create', 'edit', 'cask'
]
def match(command):

View File

@ -3,9 +3,11 @@ from thefuck.utils import for_app
@for_app('brew', at_least=2)
def match(command):
return ('update' in command.script
and "Error: This command updates brew itself" in command.output
and "Use `brew upgrade" in command.output)
return (
'update' in command.script
and "Error: This command updates brew itself" in command.output
and "Use `brew upgrade" in command.output
)
def get_new_command(command):

View File

@ -4,8 +4,10 @@ from thefuck.utils import replace_argument, for_app
@for_app('cargo', at_least=1)
def match(command):
return ('no such subcommand' in command.output.lower()
and 'Did you mean' in command.output)
return (
'no such subcommand' in command.output.lower()
and 'Did you mean' in command.output
)
def get_new_command(command):

View File

@ -21,11 +21,14 @@ def _get_sub_dirs(parent):
def match(command):
"""Match function copied from cd_mkdir.py"""
return (
command.script.startswith('cd ') and any((
'no such file or directory' in command.output.lower(),
'cd: can\'t cd to' in command.output.lower(),
'does not exist' in command.output.lower()
)))
command.script.startswith('cd ') and any(
(
'no such file or directory' in command.output.lower(),
'cd: can\'t cd to' in command.output.lower(),
'does not exist' in command.output.lower()
)
)
)
@sudo_support

View File

@ -8,11 +8,14 @@ from thefuck.shells import shell
@for_app('cd')
def match(command):
return (
command.script.startswith('cd ') and any((
'no such file or directory' in command.output.lower(),
'cd: can\'t cd to' in command.output.lower(),
'does not exist' in command.output.lower()
)))
command.script.startswith('cd ') and any(
(
'no such file or directory' in command.output.lower(),
'cd: can\'t cd to' in command.output.lower(),
'does not exist' in command.output.lower()
)
)
)
@sudo_support

View File

@ -3,10 +3,12 @@ from thefuck.shells import shell
def match(command):
return (command.script.startswith('./')
return (
command.script.startswith('./')
and 'permission denied' in command.output.lower()
and os.path.exists(command.script_parts[0])
and not os.access(command.script_parts[0], os.X_OK))
and not os.access(command.script_parts[0], os.X_OK)
)
def get_new_command(command):

View File

@ -3,8 +3,10 @@ from thefuck.utils import for_app, which
@for_app("choco", "cinst")
def match(command):
return ((command.script.startswith('choco install') or 'cinst' in command.script_parts)
and 'Installing the following packages' in command.output)
return (
(command.script.startswith('choco install') or 'cinst' in command.script_parts)
and 'Installing the following packages' in command.output
)
def get_new_command(command):

View File

@ -4,9 +4,15 @@ from thefuck.utils import replace_argument, for_app
@for_app('composer')
def match(command):
return (('did you mean this?' in command.output.lower()
or 'did you mean one of these?' in command.output.lower())) or (
"install" in command.script_parts and "composer require" in command.output.lower()
return (
(
(
'did you mean this?' in command.output.lower()
or 'did you mean one of these?' in command.output.lower()
)
) or (
"install" in command.script_parts and "composer require" in command.output.lower()
)
)

View File

@ -3,9 +3,11 @@ from thefuck.utils import for_app
@for_app('g++', 'clang++')
def match(command):
return ('This file requires compiler and library support for the '
'ISO C++ 2011 standard.' in command.output or
'-Wc++11-extensions' in command.output)
return (
'This file requires compiler and library support for the '
'ISO C++ 2011 standard.' in command.output or
'-Wc++11-extensions' in command.output
)
def get_new_command(command):

View File

@ -4,9 +4,11 @@ from thefuck.utils import for_app
from thefuck.shells import shell
tar_extensions = ('.tar', '.tar.Z', '.tar.bz2', '.tar.gz', '.tar.lz',
'.tar.lzma', '.tar.xz', '.taz', '.tb2', '.tbz', '.tbz2',
'.tgz', '.tlz', '.txz', '.tz')
tar_extensions = (
'.tar', '.tar.Z', '.tar.bz2', '.tar.gz', '.tar.lz',
'.tar.lzma', '.tar.xz', '.taz', '.tb2', '.tbz', '.tbz2',
'.tgz', '.tlz', '.txz', '.tz'
)
def _is_tar_extract(cmd):
@ -27,9 +29,11 @@ def _tar_file(cmd):
@for_app('tar')
def match(command):
return ('-C' not in command.script
and _is_tar_extract(command.script)
and _tar_file(command.script_parts) is not None)
return (
'-C' not in command.script
and _is_tar_extract(command.script)
and _tar_file(command.script_parts) is not None
)
def get_new_command(command):

View File

@ -20,9 +20,11 @@ def _parse_operations(help_text_lines):
def _get_operations():
proc = subprocess.Popen(["dnf", '--help'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc = subprocess.Popen(
["dnf", '--help'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
lines = proc.stdout.read().decode("utf-8")
return _parse_operations(lines)

View File

@ -25,14 +25,18 @@ def _get_between(content, start, end=None):
def get_new_command(command):
not_found_commands = _get_between(
command.output, 'Warning: Command(s) not found:',
'Available commands:')
'Available commands:'
)
possible_commands = _get_between(
command.output, 'Available commands:')
command.output, '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))
script = script.replace(
' {}'.format(not_found),
' {}'.format(fix)
)
return script

View File

@ -6,8 +6,10 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command):
return ('command not found' in command.output.lower()
and u' ' in command.script)
return (
'command not found' in command.output.lower()
and u' ' in command.script
)
@sudo_support

View File

@ -60,21 +60,29 @@ def match(command):
return _search(command.output)
@default_settings({'fixlinecmd': u'{editor} {file} +{line}',
'fixcolcmd': None})
@default_settings(
{
'fixlinecmd': u'{editor} {file} +{line}',
'fixcolcmd': None
}
)
def get_new_command(command):
m = _search(command.output)
# Note: there does not seem to be a standard for columns, so they are just
# ignored by default
if settings.fixcolcmd and 'col' in m.groupdict():
editor_call = settings.fixcolcmd.format(editor=os.environ['EDITOR'],
file=m.group('file'),
line=m.group('line'),
col=m.group('col'))
editor_call = settings.fixcolcmd.format(
editor=os.environ['EDITOR'],
file=m.group('file'),
line=m.group('line'),
col=m.group('col')
)
else:
editor_call = settings.fixlinecmd.format(editor=os.environ['EDITOR'],
file=m.group('file'),
line=m.group('line'))
editor_call = settings.fixlinecmd.format(
editor=os.environ['EDITOR'],
file=m.group('file'),
line=m.group('line')
)
return shell.and_(editor_call, command.script)

View File

@ -5,9 +5,11 @@ from thefuck.utils import for_app, eager, replace_command, cache, which
@for_app('gem')
def match(command):
return ('ERROR: While executing gem ... (Gem::CommandLineError)'
return (
'ERROR: While executing gem ... (Gem::CommandLineError)'
in command.output
and 'Unknown command' in command.output)
and 'Unknown command' in command.output
)
def _get_unknown_command(command):
@ -16,8 +18,10 @@ def _get_unknown_command(command):
@eager
def _get_all_commands():
proc = subprocess.Popen(['gem', 'help', 'commands'],
stdout=subprocess.PIPE)
proc = subprocess.Popen(
['gem', 'help', 'commands'],
stdout=subprocess.PIPE
)
for line in proc.stdout.readlines():
line = line.decode()

View File

@ -9,7 +9,8 @@ from thefuck.utils import memoize
def _get_missing_file(command):
pathspec = re.findall(
r"error: pathspec '([^']*)' "
r'did not match any file\(s\) known to git.', command.output)[0]
r'did not match any file\(s\) known to git.', command.output
)[0]
if Path(pathspec).exists():
return pathspec

View File

@ -4,8 +4,10 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return ('add' in command.script_parts
and 'Use -f if you really want to add them.' in command.output)
return (
'add' in command.script_parts
and 'Use -f if you really want to add them.' in command.output
)
@git_support

View File

@ -5,8 +5,10 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return ('bisect' in command.script_parts and
'usage: git bisect' in command.output)
return (
'bisect' in command.script_parts and
'usage: git bisect' in command.output
)
@git_support

View File

@ -4,8 +4,10 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return ('branch -d' in command.script
and 'If you are sure you want to delete it' in command.output)
return (
'branch -d' in command.script
and 'If you are sure you want to delete it' in command.output
)
@git_support

View File

@ -6,8 +6,10 @@ from thefuck.utils import eager
@git_support
def match(command):
return ("fatal: A branch named '" in command.output
and "' already exists." in command.output)
return (
"fatal: A branch named '" in command.output
and "' already exists." in command.output
)
@git_support
@ -16,10 +18,12 @@ def get_new_command(command):
branch_name = re.findall(
r"fatal: A branch named '(.+)' already exists.", command.output)[0]
branch_name = branch_name.replace("'", r"\'")
new_command_templates = [['git branch -d {0}', 'git branch {0}'],
['git branch -d {0}', 'git checkout -b {0}'],
['git branch -D {0}', 'git branch {0}'],
['git branch -D {0}', 'git checkout -b {0}'],
['git checkout {0}']]
new_command_templates = [
['git branch -d {0}', 'git branch {0}'],
['git branch -d {0}', 'git checkout -b {0}'],
['git branch -D {0}', 'git branch {0}'],
['git branch -D {0}', 'git checkout -b {0}'],
['git checkout {0}']
]
for new_command_template in new_command_templates:
yield shell.and_(*new_command_template).format(branch_name)

View File

@ -8,8 +8,10 @@ from thefuck.shells import shell
@git_support
def match(command):
return ('did not match any file(s) known to git' in command.output
and "Did you forget to 'git add'?" not in command.output)
return (
'did not match any file(s) known to git' in command.output
and "Did you forget to 'git add'?" not in command.output
)
def get_branches():
@ -32,8 +34,10 @@ def get_new_command(command):
missing_file = re.findall(
r"error: pathspec '([^']*)' "
r"did not match any file\(s\) known to git", command.output)[0]
closest_branch = utils.get_closest(missing_file, get_branches(),
fallback_to_first=False)
closest_branch = utils.get_closest(
missing_file, get_branches(),
fallback_to_first=False
)
new_commands = []
@ -43,7 +47,10 @@ def get_new_command(command):
new_commands.append(replace_argument(command.script, 'checkout', 'checkout -b'))
if not new_commands:
new_commands.append(shell.and_('git branch {}', '{}').format(
missing_file, command.script))
new_commands.append(
shell.and_('git branch {}', '{}').format(
missing_file, command.script
)
)
return new_commands

View File

@ -3,8 +3,10 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return (' git clone ' in command.script
and 'fatal: Too many arguments.' in command.output)
return (
' git clone ' in command.script
and 'fatal: Too many arguments.' in command.output
)
@git_support

View File

@ -4,11 +4,15 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
files = [arg for arg in command.script_parts[2:]
if not arg.startswith('-')]
return ('diff' in command.script
and '--no-index' not in command.script
and len(files) == 2)
files = [
arg for arg in command.script_parts[2:]
if not arg.startswith('-')
]
return (
'diff' in command.script
and '--no-index' not in command.script
and len(files) == 2
)
@git_support

View File

@ -4,8 +4,10 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return ('diff' in command.script and
'--staged' not in command.script)
return (
'diff' in command.script and
'--staged' not in command.script
)
@git_support

View File

@ -6,8 +6,10 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
if command.script_parts and len(command.script_parts) > 1:
return (command.script_parts[1] == 'stash'
and 'usage:' in command.output)
return (
command.script_parts[1] == 'stash'
and 'usage:' in command.output
)
else:
return False
@ -21,7 +23,8 @@ stash_commands = (
'list',
'pop',
'save',
'show')
'show'
)
@git_support

View File

@ -5,9 +5,11 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return ('merge' in command.script
and ' - not something we can merge' in command.output
and 'Did you mean this?' in command.output)
return (
'merge' in command.script
and ' - not something we can merge' in command.output
and 'Did you mean this?' in command.output
)
@git_support

View File

@ -3,8 +3,10 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return ('merge' in command.script
and 'fatal: refusing to merge unrelated histories' in command.output)
return (
'merge' in command.script
and 'fatal: refusing to merge unrelated histories' in command.output
)
@git_support

View File

@ -5,14 +5,20 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return (" is not a git command. See 'git --help'." in command.output
and ('The most similar command' in command.output
or 'Did you mean' in command.output))
return (
" is not a git command. See 'git --help'." in command.output
and (
'The most similar command' in command.output
or 'Did you mean' in command.output
)
)
@git_support
def get_new_command(command):
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
command.output)[0]
broken_cmd = re.findall(
r"git: '([^']*)' is not a git command",
command.output
)[0]
matched = get_all_matched_commands(command.output, ['The most similar command', 'Did you mean'])
return replace_command(command, broken_cmd, matched)

View File

@ -4,8 +4,10 @@ from thefuck.specific.git import git_support
@git_support
def match(command):
return ('fatal: Not a git repository' in command.output
and "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." in command.output)
return (
'fatal: Not a git repository' in command.output
and "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." in command.output
)
@git_support