mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 12:06:04 +00:00
#N/A: Add conda rule (#1138)
* add conda rules * revert * add conda * add to readme and flake * consistency with quotes and use for_app * Update thefuck/rules/conda_mistype.py Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
This commit is contained in:
parent
0c58317932
commit
fd90e69ceb
@ -184,6 +184,7 @@ following rules are enabled by default:
|
||||
* `chmod_x` – add execution bit;
|
||||
* `choco_install` – append common suffixes for chocolatey packages;
|
||||
* `composer_not_command` – fixes composer command name;
|
||||
* `conda_mistype` – fixes conda commands;
|
||||
* `cp_create_destination` – creates a new directory when you attempt to `cp` or `mv` to a non existent one
|
||||
* `cp_omitting_directory` – adds `-a` when you `cp` directory;
|
||||
* `cpp11` – adds missing `-std=c++11` to `g++` or `clang++`;
|
||||
|
24
tests/rules/test_conda_mistype.py
Normal file
24
tests/rules/test_conda_mistype.py
Normal file
@ -0,0 +1,24 @@
|
||||
import pytest
|
||||
|
||||
from thefuck.rules.conda_mistype import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mistype_response():
|
||||
return """
|
||||
|
||||
CommandNotFoundError: No command 'conda lst'.
|
||||
Did you mean 'conda list'?
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def test_match(mistype_response):
|
||||
assert match(Command('conda lst', mistype_response))
|
||||
err_response = 'bash: codna: command not found'
|
||||
assert not match(Command('codna list', err_response))
|
||||
|
||||
|
||||
def test_get_new_command(mistype_response):
|
||||
assert (get_new_command(Command('conda lst', mistype_response)) == ['conda list'])
|
17
thefuck/rules/conda_mistype.py
Normal file
17
thefuck/rules/conda_mistype.py
Normal file
@ -0,0 +1,17 @@
|
||||
import re
|
||||
from thefuck.utils import replace_command, for_app
|
||||
|
||||
|
||||
@for_app("conda")
|
||||
def match(command):
|
||||
"""
|
||||
Match a mistyped command
|
||||
"""
|
||||
return "Did you mean 'conda" in command.output
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
match = re.findall(r"'conda ([^']*)'", command.output)
|
||||
broken_cmd = match[0]
|
||||
correct_cmd = match[1]
|
||||
return replace_command(command, broken_cmd, [correct_cmd])
|
Loading…
x
Reference in New Issue
Block a user