#/N/A: Extend pyenv rule to include goenv, nodenv and rbenv (#1100)
Co-authored-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com> Co-authored-by: Divy Jain <dkj@somaiya.edu>
This commit is contained in:
committed by
GitHub
parent
fd90e69ceb
commit
0e34c2343e
@@ -1,8 +1,12 @@
|
||||
import re
|
||||
from subprocess import PIPE, Popen
|
||||
|
||||
from thefuck.utils import (cache, for_app, replace_argument, replace_command,
|
||||
which)
|
||||
from subprocess import PIPE, Popen
|
||||
|
||||
|
||||
supported_apps = 'goenv', 'nodenv', 'pyenv', 'rbenv'
|
||||
enabled_by_default = any(which(a) for a in supported_apps)
|
||||
|
||||
|
||||
COMMON_TYPOS = {
|
||||
'list': ['versions', 'install --list'],
|
||||
@@ -10,24 +14,22 @@ COMMON_TYPOS = {
|
||||
}
|
||||
|
||||
|
||||
@for_app('pyenv')
|
||||
@for_app(*supported_apps, at_least=1)
|
||||
def match(command):
|
||||
return 'pyenv: no such command' in command.output
|
||||
return 'env: no such command ' in command.output
|
||||
|
||||
|
||||
def get_pyenv_commands():
|
||||
proc = Popen(['pyenv', 'commands'], stdout=PIPE)
|
||||
def get_app_commands(app):
|
||||
proc = Popen([app, 'commands'], stdout=PIPE)
|
||||
return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]
|
||||
|
||||
|
||||
if which('pyenv'):
|
||||
get_pyenv_commands = cache(which('pyenv'))(get_pyenv_commands)
|
||||
|
||||
|
||||
@for_app('pyenv')
|
||||
def get_new_command(command):
|
||||
broken = re.findall(r"pyenv: no such command `([^']*)'", command.output)[0]
|
||||
broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0]
|
||||
matched = [replace_argument(command.script, broken, common_typo)
|
||||
for common_typo in COMMON_TYPOS.get(broken, [])]
|
||||
matched.extend(replace_command(command, broken, get_pyenv_commands()))
|
||||
|
||||
app = command.script_parts[0]
|
||||
app_commands = cache(which(app))(get_app_commands)(app)
|
||||
matched.extend(replace_command(command, broken, app_commands))
|
||||
return matched
|
||||
Reference in New Issue
Block a user