mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-07 13:41:21 +00:00
Support Linux/Windows in yarn_help
rule
See https://www.dwheeler.com/essays/open-files-urls.html and https://stackoverflow.com/questions/5226958/which-equivalent-function-in-python/15133367#15133367
This commit is contained in:
parent
35ea4dce71
commit
4b53b1d3e3
@ -1,6 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from thefuck.rules.yarn_help import match, get_new_command
|
from thefuck.rules.yarn_help import match, get_new_command
|
||||||
from tests.utils import Command
|
from tests.utils import Command
|
||||||
|
from thefuck.system import open_command
|
||||||
|
|
||||||
|
|
||||||
stdout_clean = '''
|
stdout_clean = '''
|
||||||
@ -50,6 +51,6 @@ def test_match(command):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command, new_command', [
|
@pytest.mark.parametrize('command, new_command', [
|
||||||
(Command('yarn help clean', stdout=stdout_clean), 'open https://yarnpkg.com/en/docs/cli/clean')])
|
(Command('yarn help clean', stdout=stdout_clean), open_command('https://yarnpkg.com/en/docs/cli/clean'))])
|
||||||
def test_get_new_command(command, new_command):
|
def test_get_new_command(command, new_command):
|
||||||
assert get_new_command(command) == new_command
|
assert get_new_command(command) == new_command
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
from thefuck.utils import for_app
|
from thefuck.utils import for_app
|
||||||
|
from thefuck.system import open_command
|
||||||
|
|
||||||
|
|
||||||
@for_app('yarn', at_least=2)
|
@for_app('yarn', at_least=2)
|
||||||
@ -8,6 +9,6 @@ def match(command):
|
|||||||
|
|
||||||
|
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
fix = re.findall(r'Visit ([^ ]*) for documentation about this command.', command.stdout)[0]
|
url = re.findall(r'Visit ([^ ]*) for documentation about this command.', command.stdout)[0]
|
||||||
|
|
||||||
return 'open ' + fix
|
return open_command(url)
|
||||||
|
@ -3,6 +3,7 @@ import sys
|
|||||||
import tty
|
import tty
|
||||||
import termios
|
import termios
|
||||||
import colorama
|
import colorama
|
||||||
|
from distutils.spawn import find_executable
|
||||||
from .. import const
|
from .. import const
|
||||||
|
|
||||||
init_output = colorama.init
|
init_output = colorama.init
|
||||||
@ -35,6 +36,13 @@ def get_key():
|
|||||||
|
|
||||||
return ch
|
return ch
|
||||||
|
|
||||||
|
|
||||||
|
def open_command(arg):
|
||||||
|
if (find_executable('xdg-open')):
|
||||||
|
return 'xdg-open ' + arg
|
||||||
|
return 'open ' + arg
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -26,6 +26,11 @@ def get_key():
|
|||||||
encoding = sys.stdout.encoding or os.environ.get('PYTHONIOENCODING', 'utf-8')
|
encoding = sys.stdout.encoding or os.environ.get('PYTHONIOENCODING', 'utf-8')
|
||||||
return ch.decode(encoding)
|
return ch.decode(encoding)
|
||||||
|
|
||||||
|
|
||||||
|
def open_command(arg):
|
||||||
|
return 'cmd /c start ' + arg
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user