mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 06:38:32 +00:00
Merge cbfa1ae196d76da675c6a664e3ba6571b32c0d5e into c7e7e1d884d3bb241ea6448f72a989434c2a35ec
This commit is contained in:
commit
57f5db675b
@ -340,6 +340,7 @@ following rules are enabled by default:
|
||||
* `tmux` – fixes `tmux` commands;
|
||||
* `unknown_command` – fixes hadoop hdfs-style "unknown command", for example adds missing '-' to the command on `hdfs dfs ls`;
|
||||
* `unsudo` – removes `sudo` from previous command if a process refuses to run on superuser privilege.
|
||||
* `upper_to_lower_case` – replaces the uppercase letters with lowercase, so the command is correct;
|
||||
* `vagrant_up` – starts up the vagrant instance;
|
||||
* `whois` – fixes `whois` command;
|
||||
* `workon_doesnt_exists` – fixes `virtualenvwrapper` env name os suggests to create new.
|
||||
|
44
tests/rules/test_upper_to_lower_case.py
Normal file
44
tests/rules/test_upper_to_lower_case.py
Normal file
@ -0,0 +1,44 @@
|
||||
import pytest
|
||||
|
||||
from thefuck.rules.upper_to_lower_case import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output",
|
||||
[
|
||||
("LS", "command not found"),
|
||||
("LS -A", "command not found"),
|
||||
],
|
||||
)
|
||||
def test_match(script, output):
|
||||
assert match(Command(script, output))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output",
|
||||
[
|
||||
("ls", ""),
|
||||
("cd thefuck", ""),
|
||||
("mv tests testing", ""),
|
||||
("git add .", ""),
|
||||
],
|
||||
)
|
||||
def test_not_match(script, output):
|
||||
assert not match(Command(script, output))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output, new_command",
|
||||
[
|
||||
("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):
|
||||
assert get_new_command(Command(script, output)) == new_command
|
21
thefuck/rules/upper_to_lower_case.py
Normal file
21
thefuck/rules/upper_to_lower_case.py
Normal file
@ -0,0 +1,21 @@
|
||||
from thefuck.utils import get_all_executables, which
|
||||
|
||||
# this rule is activated when the typed command is
|
||||
# in uppercase letters and if the command is not
|
||||
# executed. However in order to activate this rule
|
||||
# it is necessary the first word of the whole command
|
||||
# to be valid.
|
||||
def match(command):
|
||||
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()))
|
||||
|
||||
# returns the same command in lowercase letters
|
||||
def get_new_command(cmd):
|
||||
return cmd.script.lower()
|
||||
|
||||
|
||||
requires_output = False
|
||||
priority = 100
|
Loading…
x
Reference in New Issue
Block a user