mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 01:28:56 +00:00
Refactor commit
This commit is contained in:
parent
e8905a5a54
commit
eacc9c3cad
@ -9,9 +9,24 @@ def output(goenv_cmd):
|
|||||||
return "goenv: no such command '{}'".format(goenv_cmd)
|
return "goenv: no such command '{}'".format(goenv_cmd)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def Popen(mocker):
|
||||||
|
mock = mocker.patch('thefuck.rules.pyenv_no_such_command.Popen')
|
||||||
|
mock.return_value.stdout.readlines.return_value = (
|
||||||
|
b'--version\nactivate\ncommands\ncompletions\ndeactivate\nexec_\n'
|
||||||
|
b'global\nhelp\nhooks\ninit\ninstall\nlocal\nprefix_\n'
|
||||||
|
b'realpath.dylib\nrehash\nroot\nshell\nshims\nuninstall\nversion_\n'
|
||||||
|
b'version-file\nversion-file-read\nversion-file-write\nversion-name_\n'
|
||||||
|
b'version-origin\nversions\nvirtualenv\nvirtualenv-delete_\n'
|
||||||
|
b'virtualenv-init\nvirtualenv-prefix\nvirtualenvs_\n'
|
||||||
|
b'virtualenvwrapper\nvirtualenvwrapper_lazy\nwhence\nwhich_\n'
|
||||||
|
).split()
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script, goenv_cmd', [
|
@pytest.mark.parametrize('script, goenv_cmd', [
|
||||||
('goenv globe', 'globe'),
|
('goenv globe', 'globe'),
|
||||||
('goenv intall 1.4.0', 'intall'),
|
('goenv intall 3.8.0', 'intall'),
|
||||||
('goenv list', 'list'),
|
('goenv list', 'list'),
|
||||||
])
|
])
|
||||||
def test_match(script, goenv_cmd, output):
|
def test_match(script, goenv_cmd, output):
|
||||||
@ -20,8 +35,8 @@ def test_match(script, goenv_cmd, output):
|
|||||||
|
|
||||||
@pytest.mark.parametrize('script, output', [
|
@pytest.mark.parametrize('script, output', [
|
||||||
('goenv global', 'system'),
|
('goenv global', 'system'),
|
||||||
('goenv versions', ' 1.5.0\n 1.5.1\n* 1.5.2\n'),
|
('goenv versions', ' 3.7.0\n 3.7.1\n* 3.7.2\n'),
|
||||||
('goenv install --list', ' 1.5.0\n 1.5.1\n 1.5.2\n'),
|
('goenv install --list', ' 3.7.0\n 3.7.1\n 3.7.2\n'),
|
||||||
])
|
])
|
||||||
def test_not_match(script, output):
|
def test_not_match(script, output):
|
||||||
assert not match(Command(script, output=output))
|
assert not match(Command(script, output=output))
|
||||||
|
@ -9,6 +9,21 @@ def output(nodenv_cmd):
|
|||||||
return "nodenv: no such command `{}'".format(nodenv_cmd)
|
return "nodenv: no such command `{}'".format(nodenv_cmd)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def Popen(mocker):
|
||||||
|
mock = mocker.patch('thefuck.rules.pyenv_no_such_command.Popen')
|
||||||
|
mock.return_value.stdout.readlines.return_value = (
|
||||||
|
b'--version\nactivate\ncommands\ncompletions\ndeactivate\nexec_\n'
|
||||||
|
b'global\nhelp\nhooks\ninit\ninstall\nlocal\nprefix_\n'
|
||||||
|
b'realpath.dylib\nrehash\nroot\nshell\nshims\nuninstall\nversion_\n'
|
||||||
|
b'version-file\nversion-file-read\nversion-file-write\nversion-name_\n'
|
||||||
|
b'version-origin\nversions\nvirtualenv\nvirtualenv-delete_\n'
|
||||||
|
b'virtualenv-init\nvirtualenv-prefix\nvirtualenvs_\n'
|
||||||
|
b'virtualenvwrapper\nvirtualenvwrapper_lazy\nwhence\nwhich_\n'
|
||||||
|
).split()
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script, nodenv_cmd', [
|
@pytest.mark.parametrize('script, nodenv_cmd', [
|
||||||
('nodenv globe', 'globe'),
|
('nodenv globe', 'globe'),
|
||||||
('nodenv intall 3.8.0', 'intall'),
|
('nodenv intall 3.8.0', 'intall'),
|
||||||
|
@ -9,6 +9,21 @@ def output(pyenv_cmd):
|
|||||||
return "pyenv: no such command `{}'".format(pyenv_cmd)
|
return "pyenv: no such command `{}'".format(pyenv_cmd)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def Popen(mocker):
|
||||||
|
mock = mocker.patch('thefuck.rules.pyenv_no_such_command.Popen')
|
||||||
|
mock.return_value.stdout.readlines.return_value = (
|
||||||
|
b'--version\nactivate\ncommands\ncompletions\ndeactivate\nexec_\n'
|
||||||
|
b'global\nhelp\nhooks\ninit\ninstall\nlocal\nprefix_\n'
|
||||||
|
b'realpath.dylib\nrehash\nroot\nshell\nshims\nuninstall\nversion_\n'
|
||||||
|
b'version-file\nversion-file-read\nversion-file-write\nversion-name_\n'
|
||||||
|
b'version-origin\nversions\nvirtualenv\nvirtualenv-delete_\n'
|
||||||
|
b'virtualenv-init\nvirtualenv-prefix\nvirtualenvs_\n'
|
||||||
|
b'virtualenvwrapper\nvirtualenvwrapper_lazy\nwhence\nwhich_\n'
|
||||||
|
).split()
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script, pyenv_cmd', [
|
@pytest.mark.parametrize('script, pyenv_cmd', [
|
||||||
('pyenv globe', 'globe'),
|
('pyenv globe', 'globe'),
|
||||||
('pyenv intall 3.8.0', 'intall'),
|
('pyenv intall 3.8.0', 'intall'),
|
||||||
|
@ -9,6 +9,21 @@ def output(rbenv_cmd):
|
|||||||
return "rbenv: no such command `{}'".format(rbenv_cmd)
|
return "rbenv: no such command `{}'".format(rbenv_cmd)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def Popen(mocker):
|
||||||
|
mock = mocker.patch('thefuck.rules.pyenv_no_such_command.Popen')
|
||||||
|
mock.return_value.stdout.readlines.return_value = (
|
||||||
|
b'--version\nactivate\ncommands\ncompletions\ndeactivate\nexec_\n'
|
||||||
|
b'global\nhelp\nhooks\ninit\ninstall\nlocal\nprefix_\n'
|
||||||
|
b'realpath.dylib\nrehash\nroot\nshell\nshims\nuninstall\nversion_\n'
|
||||||
|
b'version-file\nversion-file-read\nversion-file-write\nversion-name_\n'
|
||||||
|
b'version-origin\nversions\nvirtualenv\nvirtualenv-delete_\n'
|
||||||
|
b'virtualenv-init\nvirtualenv-prefix\nvirtualenvs_\n'
|
||||||
|
b'virtualenvwrapper\nvirtualenvwrapper_lazy\nwhence\nwhich_\n'
|
||||||
|
).split()
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script, rbenv_cmd', [
|
@pytest.mark.parametrize('script, rbenv_cmd', [
|
||||||
('rbenv globe', 'globe'),
|
('rbenv globe', 'globe'),
|
||||||
('rbenv intall 3.8.0', 'intall'),
|
('rbenv intall 3.8.0', 'intall'),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
from thefuck.utils import cache, for_app, replace_argument, replace_command, which
|
from thefuck.utils import cache, for_app, replace_argument, replace_command, which
|
||||||
from thefuck.specific.devenv import env_available, COMMON_TYPOS, get_commands
|
from thefuck.specific.devenv import env_available, COMMON_TYPOS
|
||||||
|
from subprocess import PIPE, Popen
|
||||||
|
|
||||||
enabled_by_default = env_available
|
enabled_by_default = env_available
|
||||||
|
|
||||||
@ -10,6 +11,11 @@ def match(command):
|
|||||||
return 'goenv: no such command' in command.output
|
return 'goenv: no such command' in command.output
|
||||||
|
|
||||||
|
|
||||||
|
def get_commands():
|
||||||
|
proc = Popen(['goenv', 'commands'], stdout=PIPE)
|
||||||
|
return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]
|
||||||
|
|
||||||
|
|
||||||
if which('goenv'):
|
if which('goenv'):
|
||||||
get_commands = cache(which('goenv'))(get_commands)
|
get_commands = cache(which('goenv'))(get_commands)
|
||||||
|
|
||||||
@ -19,5 +25,5 @@ def get_new_command(command):
|
|||||||
broken = re.findall(r"goenv: no such command '([^']*)'", command.output)[0]
|
broken = re.findall(r"goenv: no such command '([^']*)'", command.output)[0]
|
||||||
matched = [replace_argument(command.script, broken, common_typo)
|
matched = [replace_argument(command.script, broken, common_typo)
|
||||||
for common_typo in COMMON_TYPOS.get(broken, [])]
|
for common_typo in COMMON_TYPOS.get(broken, [])]
|
||||||
matched.extend(replace_command(command, broken, get_commands(command.script_parts[0])))
|
matched.extend(replace_command(command, broken, get_commands()))
|
||||||
return matched
|
return matched
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
from thefuck.utils import cache, for_app, replace_argument, replace_command, which
|
from thefuck.utils import cache, for_app, replace_argument, replace_command, which
|
||||||
from thefuck.specific.devenv import env_available, COMMON_TYPOS, get_commands
|
from thefuck.specific.devenv import env_available, COMMON_TYPOS
|
||||||
|
from subprocess import PIPE, Popen
|
||||||
|
|
||||||
enabled_by_default = env_available
|
enabled_by_default = env_available
|
||||||
|
|
||||||
@ -10,6 +11,11 @@ def match(command):
|
|||||||
return 'nodenv: no such command' in command.output
|
return 'nodenv: no such command' in command.output
|
||||||
|
|
||||||
|
|
||||||
|
def get_commands():
|
||||||
|
proc = Popen(['nodenv', 'commands'], stdout=PIPE)
|
||||||
|
return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]
|
||||||
|
|
||||||
|
|
||||||
if which('nodenv'):
|
if which('nodenv'):
|
||||||
get_commands = cache(which('nodenv'))(get_commands)
|
get_commands = cache(which('nodenv'))(get_commands)
|
||||||
|
|
||||||
@ -19,5 +25,5 @@ def get_new_command(command):
|
|||||||
broken = re.findall(r"nodenv: no such command `([^']*)'", command.output)[0]
|
broken = re.findall(r"nodenv: no such command `([^']*)'", command.output)[0]
|
||||||
matched = [replace_argument(command.script, broken, common_typo)
|
matched = [replace_argument(command.script, broken, common_typo)
|
||||||
for common_typo in COMMON_TYPOS.get(broken, [])]
|
for common_typo in COMMON_TYPOS.get(broken, [])]
|
||||||
matched.extend(replace_command(command, broken, get_commands(command.script_parts[0])))
|
matched.extend(replace_command(command, broken, get_commands()))
|
||||||
return matched
|
return matched
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
from thefuck.utils import cache, for_app, replace_argument, replace_command, which
|
from thefuck.utils import cache, for_app, replace_argument, replace_command, which
|
||||||
from thefuck.specific.devenv import env_available, COMMON_TYPOS, get_commands
|
from thefuck.specific.devenv import env_available, COMMON_TYPOS
|
||||||
|
from subprocess import PIPE, Popen
|
||||||
|
|
||||||
enabled_by_default = env_available
|
enabled_by_default = env_available
|
||||||
|
|
||||||
@ -10,6 +11,11 @@ def match(command):
|
|||||||
return 'pyenv: no such command' in command.output
|
return 'pyenv: no such command' in command.output
|
||||||
|
|
||||||
|
|
||||||
|
def get_commands():
|
||||||
|
proc = Popen(['pyenv', 'commands'], stdout=PIPE)
|
||||||
|
return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]
|
||||||
|
|
||||||
|
|
||||||
if which('pyenv'):
|
if which('pyenv'):
|
||||||
get_commands = cache(which('pyenv'))(get_commands)
|
get_commands = cache(which('pyenv'))(get_commands)
|
||||||
|
|
||||||
@ -19,5 +25,5 @@ def get_new_command(command):
|
|||||||
broken = re.findall(r"pyenv: no such command `([^']*)'", command.output)[0]
|
broken = re.findall(r"pyenv: no such command `([^']*)'", command.output)[0]
|
||||||
matched = [replace_argument(command.script, broken, common_typo)
|
matched = [replace_argument(command.script, broken, common_typo)
|
||||||
for common_typo in COMMON_TYPOS.get(broken, [])]
|
for common_typo in COMMON_TYPOS.get(broken, [])]
|
||||||
matched.extend(replace_command(command, broken, get_commands('pyenv')))
|
matched.extend(replace_command(command, broken, get_commands()))
|
||||||
return matched
|
return matched
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
from thefuck.utils import cache, for_app, replace_argument, replace_command, which
|
from thefuck.utils import cache, for_app, replace_argument, replace_command, which
|
||||||
from thefuck.specific.devenv import env_available, COMMON_TYPOS, get_commands
|
from thefuck.specific.devenv import env_available, COMMON_TYPOS
|
||||||
|
from subprocess import PIPE, Popen
|
||||||
|
|
||||||
enabled_by_default = env_available
|
enabled_by_default = env_available
|
||||||
|
|
||||||
@ -10,6 +11,11 @@ def match(command):
|
|||||||
return 'rbenv: no such command' in command.output
|
return 'rbenv: no such command' in command.output
|
||||||
|
|
||||||
|
|
||||||
|
def get_commands():
|
||||||
|
proc = Popen(['rbenv', 'commands'], stdout=PIPE)
|
||||||
|
return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]
|
||||||
|
|
||||||
|
|
||||||
if which('rbenv'):
|
if which('rbenv'):
|
||||||
get_commands = cache(which('rbenv'))(get_commands)
|
get_commands = cache(which('rbenv'))(get_commands)
|
||||||
|
|
||||||
@ -19,5 +25,5 @@ def get_new_command(command):
|
|||||||
broken = re.findall(r"rbenv: no such command `([^']*)'", command.output)[0]
|
broken = re.findall(r"rbenv: no such command `([^']*)'", command.output)[0]
|
||||||
matched = [replace_argument(command.script, broken, common_typo)
|
matched = [replace_argument(command.script, broken, common_typo)
|
||||||
for common_typo in COMMON_TYPOS.get(broken, [])]
|
for common_typo in COMMON_TYPOS.get(broken, [])]
|
||||||
matched.extend(replace_command(command, broken, get_commands(command.script_parts[0])))
|
matched.extend(replace_command(command, broken, get_commands()))
|
||||||
return matched
|
return matched
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from thefuck.utils import which
|
from thefuck.utils import which
|
||||||
from subprocess import Popen, PIPE
|
|
||||||
|
|
||||||
|
|
||||||
env_available = bool(which('pyenv')) or bool(which('rbenv')) or bool(which('goenv')) or bool(which('nodenv'))
|
env_available = bool(which('pyenv')) or bool(which('rbenv')) or bool(which('goenv')) or bool(which('nodenv'))
|
||||||
@ -9,8 +8,3 @@ COMMON_TYPOS = {
|
|||||||
'list': ['versions', 'install --list'],
|
'list': ['versions', 'install --list'],
|
||||||
'remove': ['uninstall'],
|
'remove': ['uninstall'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_commands(app):
|
|
||||||
proc = Popen([app, 'commands'], stdout=PIPE)
|
|
||||||
return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user