1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 02:01:13 +00:00

fix the rule

This commit is contained in:
Nikos Kakonas 2022-05-19 20:53:43 +00:00
parent 5d03f9f789
commit d898a4df69
2 changed files with 16 additions and 58 deletions

View File

@ -10,13 +10,6 @@ from thefuck.types import Command
[
("LS", "command not found"),
("LS -A", "command not found"),
("CD TESTS", "command not found"),
("CD tests", "command not found"),
("CAT README.MD", "command not found"),
("CAT README.md", "command not found"),
("MV TESTS TESTING", "command not found"),
("GIT ADD .", "command not found"),
("GIT add .", "command not found"),
],
)
def test_match(script, output):
@ -39,10 +32,12 @@ def test_not_match(script, output):
@pytest.mark.parametrize(
"script, output, new_command",
[
("LS", "command not found", ["ls"]),
("CD TESTS", "command not found", ["cd tests", "cd TESTS"]),
("CAT README.MD", "command not found", ["cat readme.md", "cat README.MD"]),
("GIT ADD .", "command not found", ["git add ."]),
("LS", "command not found", "ls"),
("CD TESTS", "command not found", "cd tests"),
("CAT README.MD", "command not found", "cat readme.md"),
("GIT ADD .", "command not found", "git add ."),
("GIT ADD .", "command not found", "git add ."),
("MV TESTS TESTING", "command not found", "mv tests testing"),
],
)
def test_get_new_command(script, output, new_command):

View File

@ -1,54 +1,17 @@
import subprocess
import itertools
def find_all_possible_commands(command):
lower_command = command.script.lower().split()
upper_command = command.script.upper().split()
all_commands = []
for i in lower_command:
all_commands.append(i)
for i in upper_command:
all_commands.append(i)
permutations = itertools.permutations(all_commands, len(lower_command))
new_commands = []
for per in permutations:
new_command = ""
for word in per:
new_command += word + " "
new_command = new_command.strip()
if new_command not in new_commands:
new_commands.append(new_command)
return new_commands
def find_all_correct_commands(new_commands : list):
all_correct_commands = []
for com in new_commands:
result = subprocess.getstatusoutput(com)
if result[0] == 0:
all_correct_commands.append(com)
return all_correct_commands
from thefuck.utils import get_all_executables, which
def match(command):
flag = False
for i in command.script:
if i.isupper():
flag = True
# checks if the command that typed is valid, if it is not it retunrs false
# So if we type: SL -A (instead of LS -A) the rule will not be activated
new_commands = find_all_possible_commands(command)
all_correct_commands = find_all_correct_commands(new_commands)
if len(all_correct_commands) == 0:
flag = False
return flag
return (command.script.isupper()
and not which(command.script_parts[0])
and ('not found' in command.output
or 'is not recognized as' in command.output)
and (command.script_parts[0].lower() in get_all_executables()))
def get_new_command(command):
new_commands = find_all_possible_commands(command)
all_correct_commands = find_all_correct_commands(new_commands)
return all_correct_commands
def get_new_command(cmd):
return cmd.script.lower()
priority = 900
requires_output = False
priority = 100