Add yarn_command_not_found rule
This addresses https://github.com/nvbn/thefuck/pull/607#issuecomment-283945505 The code was adapted from the `grunt_task_not_found` rule
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import re
|
||||
from subprocess import Popen, PIPE
|
||||
from thefuck.utils import for_app, eager, get_closest
|
||||
|
||||
regex = re.compile(r'error Command "(.*)" not found.')
|
||||
|
||||
|
||||
@for_app('yarn')
|
||||
def match(command):
|
||||
return regex.findall(command.stderr)
|
||||
|
||||
|
||||
@eager
|
||||
def _get_all_tasks():
|
||||
proc = Popen(['yarn', '--help'], stdout=PIPE)
|
||||
should_yield = False
|
||||
for line in proc.stdout.readlines():
|
||||
line = line.decode().strip()
|
||||
|
||||
if 'Commands:' in line:
|
||||
should_yield = True
|
||||
continue
|
||||
|
||||
if should_yield and '- ' in line:
|
||||
yield line.split(' ')[-1]
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
misspelled_task = regex.findall(command.stderr)[0]
|
||||
tasks = _get_all_tasks()
|
||||
fixed = get_closest(misspelled_task, tasks)
|
||||
return command.script.replace(' {}'.format(misspelled_task),
|
||||
' {}'.format(fixed))
|
||||
Reference in New Issue
Block a user