mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 04:18:55 +00:00
#637: Suggest yarn add
on yarn require
This commit is contained in:
parent
1b05a497e8
commit
b54cdf7c49
@ -106,6 +106,13 @@ def test_not_match(command):
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, result', [
|
||||
(Command('yarn whyy webpack', stderr=stderr('whyy')), 'yarn why webpack')])
|
||||
(Command('yarn whyy webpack', stderr=stderr('whyy')),
|
||||
'yarn why webpack'),
|
||||
(Command('yarn require lodash', stderr=stderr('require')),
|
||||
'yarn add lodash')])
|
||||
def test_get_new_command(command, result):
|
||||
assert get_new_command(command)[0] == result
|
||||
fixed_command = get_new_command(command)
|
||||
if isinstance(fixed_command, list):
|
||||
fixed_command = fixed_command[0]
|
||||
|
||||
assert fixed_command == result
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user