Skip to content

Commit fd90e69

Browse files
cjmartianscorphus
andauthored
#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 <[email protected]>
1 parent 0c58317 commit fd90e69

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ following rules are enabled by default:
184184
* `chmod_x` &ndash; add execution bit;
185185
* `choco_install` &ndash; append common suffixes for chocolatey packages;
186186
* `composer_not_command` &ndash; fixes composer command name;
187+
* `conda_mistype` &ndash; fixes conda commands;
187188
* `cp_create_destination` &ndash; creates a new directory when you attempt to `cp` or `mv` to a non existent one
188189
* `cp_omitting_directory` &ndash; adds `-a` when you `cp` directory;
189190
* `cpp11` &ndash; adds missing `-std=c++11` to `g++` or `clang++`;

tests/rules/test_conda_mistype.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
3+
from thefuck.rules.conda_mistype import match, get_new_command
4+
from thefuck.types import Command
5+
6+
7+
@pytest.fixture
8+
def mistype_response():
9+
return """
10+
11+
CommandNotFoundError: No command 'conda lst'.
12+
Did you mean 'conda list'?
13+
14+
"""
15+
16+
17+
def test_match(mistype_response):
18+
assert match(Command('conda lst', mistype_response))
19+
err_response = 'bash: codna: command not found'
20+
assert not match(Command('codna list', err_response))
21+
22+
23+
def test_get_new_command(mistype_response):
24+
assert (get_new_command(Command('conda lst', mistype_response)) == ['conda list'])

thefuck/rules/conda_mistype.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import re
2+
from thefuck.utils import replace_command, for_app
3+
4+
5+
@for_app("conda")
6+
def match(command):
7+
"""
8+
Match a mistyped command
9+
"""
10+
return "Did you mean 'conda" in command.output
11+
12+
13+
def get_new_command(command):
14+
match = re.findall(r"'conda ([^']*)'", command.output)
15+
broken_cmd = match[0]
16+
correct_cmd = match[1]
17+
return replace_command(command, broken_cmd, [correct_cmd])

0 commit comments

Comments
 (0)