1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

#977: Add wrong_hyphen_before_subcommand rule

Co-authored-by: user <avi.salmon@intel.com>
Co-authored-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
This commit is contained in:
Yotam Salmon 2021-08-08 00:26:36 +03:00 committed by GitHub
parent 8fa10b1049
commit 2a166a7dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 0 deletions

View File

@ -336,6 +336,7 @@ following rules are enabled by default:
* `vagrant_up` &ndash; starts up the vagrant instance;
* `whois` &ndash; fixes `whois` command;
* `workon_doesnt_exists` &ndash; fixes `virtualenvwrapper` env name os suggests to create new.
* `wrong_hyphen_before_subcommand` &ndash; removes an improperly placed hyphen (`apt-install` -> `apt install`, `git-log` -> `git log`, etc.)
* `yarn_alias` &ndash; fixes aliased `yarn` commands like `yarn ls`;
* `yarn_command_not_found` &ndash; fixes misspelled `yarn` commands;
* `yarn_command_replaced` &ndash; fixes replaced `yarn` commands;

View File

@ -0,0 +1,30 @@
import pytest
from thefuck.rules.wrong_hyphen_before_subcommand import match, get_new_command
from thefuck.types import Command
@pytest.fixture(autouse=True)
def get_all_executables(mocker):
mocker.patch(
"thefuck.rules.wrong_hyphen_before_subcommand.get_all_executables",
return_value=["git", "apt", "apt-get", "ls", "pwd"],
)
@pytest.mark.parametrize("script", ["git-log", "apt-install python"])
def test_match(script):
assert match(Command(script, ""))
@pytest.mark.parametrize("script", ["ls -la", "git2-make", "apt-get install python"])
def test_not_match(script):
assert not match(Command(script, ""))
@pytest.mark.parametrize(
"script, new_command",
[("git-log", "git log"), ("apt-install python", "apt install python")],
)
def test_get_new_command(script, new_command):
assert get_new_command(Command(script, "")) == new_command

View File

@ -0,0 +1,20 @@
from thefuck.utils import get_all_executables
from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command):
first_part = command.script_parts[0]
if "-" not in first_part or first_part in get_all_executables():
return False
cmd, _ = first_part.split("-", 1)
return cmd in get_all_executables()
@sudo_support
def get_new_command(command):
return command.script.replace("-", " ", 1)
priority = 4500
requires_output = False