#637: Suggest yarn add on yarn require

This commit is contained in:
Vladimir Iakovlev
2017-05-10 15:32:11 +02:00
parent 1b05a497e8
commit b54cdf7c49
2 changed files with 19 additions and 5 deletions
+10 -3
View File
@@ -1,6 +1,6 @@
import re
from subprocess import Popen, PIPE
from thefuck.utils import for_app, eager, replace_command
from thefuck.utils import for_app, eager, replace_command, replace_argument
regex = re.compile(r'error Command "(.*)" not found.')
@@ -10,6 +10,9 @@ def match(command):
return regex.findall(command.stderr)
npm_commands = {'require': 'add'}
@eager
def _get_all_tasks():
proc = Popen(['yarn', '--help'], stdout=PIPE)
@@ -27,5 +30,9 @@ def _get_all_tasks():
def get_new_command(command):
misspelled_task = regex.findall(command.stderr)[0]
tasks = _get_all_tasks()
return replace_command(command, misspelled_task, tasks)
if misspelled_task in npm_commands:
yarn_command = npm_commands[misspelled_task]
return replace_argument(command.script, misspelled_task, yarn_command)
else:
tasks = _get_all_tasks()
return replace_command(command, misspelled_task, tasks)