mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-13 22:28:33 +00:00
Make git_not_command stderr detection backward-compatible
This commit is contained in:
parent
76600cf40a
commit
b6ed499103
@ -6,12 +6,13 @@ from thefuck.specific.git import git_support
|
||||
@git_support
|
||||
def match(command):
|
||||
return (" is not a git command. See 'git --help'." in command.stderr
|
||||
and 'The most similar command' in command.stderr)
|
||||
and ('The most similar command' in command.stderr
|
||||
or 'Did you mean' in command.stderr))
|
||||
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
|
||||
command.stderr)[0]
|
||||
matched = get_all_matched_commands(command.stderr, 'The most similar command')
|
||||
matched = get_all_matched_commands(command.stderr, ['The most similar command', 'Did you mean'])
|
||||
return replace_command(command, broken_cmd, matched)
|
||||
|
@ -141,12 +141,17 @@ def eager(fn, *args, **kwargs):
|
||||
|
||||
@eager
|
||||
def get_all_matched_commands(stderr, separator='Did you mean'):
|
||||
if not isinstance(separator, list):
|
||||
separator = [separator]
|
||||
should_yield = False
|
||||
for line in stderr.split('\n'):
|
||||
if separator in line:
|
||||
should_yield = True
|
||||
elif should_yield and line:
|
||||
yield line.strip()
|
||||
for sep in separator:
|
||||
if sep in line:
|
||||
should_yield = True
|
||||
break
|
||||
else:
|
||||
if should_yield and line:
|
||||
yield line.strip()
|
||||
|
||||
|
||||
def replace_command(command, broken, matched):
|
||||
|
Loading…
x
Reference in New Issue
Block a user