mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-19 09:10:47 +01:00
More generic a solution, now works with any command that follows the same pattern of error message
This commit is contained in:
parent
2cdfe105fb
commit
c08a8bddc9
@ -22,9 +22,14 @@ def test_not_match(command):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command, new_command', [
|
@pytest.mark.parametrize('command, new_command', [
|
||||||
(Command('hdfs dfs ls'), 'hdfs dfs -ls'),
|
(Command('hdfs dfs ls',
|
||||||
(Command('hdfs dfs ls /foo/bar'), 'hdfs dfs -ls /foo/bar'),
|
stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['hdfs dfs -ls']),
|
||||||
(Command('./bin/hdfs dfs ls -R /foo/bar'), './bin/hdfs dfs -ls -R /foo/bar')])
|
(Command('hdfs dfs rm /foo/bar',
|
||||||
|
stderr='rm: Unknown command\nDid you mean -rm? This command begins with a dash.'), ['hdfs dfs -rm /foo/bar']),
|
||||||
|
(Command('./bin/hdfs dfs ls -R /foo/bar',
|
||||||
|
stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -ls -R /foo/bar']),
|
||||||
|
(Command('./bin/hdfs dfs -Dtest=fred ls -R /foo/bar',
|
||||||
|
stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -Dtest=fred -ls -R /foo/bar'])])
|
||||||
def test_get_new_command(command, new_command):
|
def test_get_new_command(command, new_command):
|
||||||
assert get_new_command(command, None) == new_command
|
assert get_new_command(command, None) == new_command
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
import re
|
||||||
|
from thefuck.utils import (replace_command, get_all_matched_commands)
|
||||||
|
|
||||||
def match(command, settings):
|
def match(command, settings):
|
||||||
return ('hdfs dfs' in command.script
|
return (re.search(r"([^:]*): Unknown command.*", command.stderr) != None
|
||||||
and "this command begins with a dash." in command.stderr.lower())
|
and re.search(r"Did you mean ([^?]*)?", command.stderr) != None)
|
||||||
|
|
||||||
|
|
||||||
def get_new_command(command, settings):
|
def get_new_command(command, settings):
|
||||||
data = command.script.split()
|
broken_cmd = re.findall(r"([^:]*): Unknown command.*", command.stderr)[0]
|
||||||
data[2] = '-' + data[2]
|
matched = re.findall(r"Did you mean ([^?]*)?", command.stderr)
|
||||||
return ' '.join(data)
|
return replace_command(command, broken_cmd, matched)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user