mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 04:18:55 +00:00
Add handler for "is not a git command"
This commit is contained in:
parent
9ed022d67f
commit
e7b377a310
@ -36,6 +36,15 @@ zsh: command not found: puthon
|
||||
➜ fuck
|
||||
Python 3.4.2 (default, Oct 8 2014, 13:08:17)
|
||||
...
|
||||
|
||||
➜ git brnch
|
||||
git: 'brnch' is not a git command. See 'git --help'.
|
||||
|
||||
Did you mean this?
|
||||
branch
|
||||
|
||||
➜ fuck
|
||||
* master
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
|
||||
setup(name='thefuck',
|
||||
version=1.2,
|
||||
version=1.3,
|
||||
description="Magnificent app which corrects your previous console command",
|
||||
author='Vladimir Iakovlev',
|
||||
author_email='nvbn.rm@gmail.com',
|
||||
|
28
tests/rules/test_git_not_command.py
Normal file
28
tests/rules/test_git_not_command.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
from thefuck.main import Command
|
||||
from thefuck.rules.git_not_command import match, get_new_command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_not_command():
|
||||
return """git: 'brnch' is not a git command. See 'git --help'.
|
||||
|
||||
Did you mean this?
|
||||
branch
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_command():
|
||||
return "* master"
|
||||
|
||||
|
||||
def test_match(git_not_command, git_command):
|
||||
assert match(Command('git brnch', '', git_not_command), None)
|
||||
assert not match(Command('ls brnch', '', git_not_command), None)
|
||||
assert not match(Command('git branch', '', git_command), None)
|
||||
|
||||
|
||||
def test_get_new_command(git_not_command):
|
||||
assert get_new_command(Command('git brnch', '', git_not_command), None)\
|
||||
== 'git branch'
|
16
thefuck/rules/git_not_command.py
Normal file
16
thefuck/rules/git_not_command.py
Normal file
@ -0,0 +1,16 @@
|
||||
import re
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
return ('git' in command.script
|
||||
and " is not a git command. See 'git --help'." in command.stderr
|
||||
and 'Did you mean this?' in command.stderr)
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
|
||||
command.stderr)[0]
|
||||
new_cmd = re.findall(r'Did you mean this\?\n\s*([^\n]*)',
|
||||
command.stderr)[0]
|
||||
return command.script.replace(broken_cmd, new_cmd, 1)
|
||||
|
@ -22,4 +22,4 @@ def get_new_command(command, settings):
|
||||
output)[0]
|
||||
fixed_name = re.findall(r"Command '([^']*)' from package",
|
||||
output)[0]
|
||||
return command.script.replace(broken_name, fixed_name)
|
||||
return command.script.replace(broken_name, fixed_name, 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user