mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 04:18:55 +00:00
#N/A: Update react_native_command_unrecognized
rule
This commit is contained in:
parent
1f1b7da6f4
commit
503c903822
@ -1,25 +1,39 @@
|
||||
import pytest
|
||||
from io import BytesIO
|
||||
from thefuck.rules.react_native_command_unrecognized import match, \
|
||||
get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
stderr = 'Command `{}` unrecognized'.format
|
||||
stderr = "Unrecognized command '{}'".format
|
||||
|
||||
stdout = '''
|
||||
Usage: react-native <command>
|
||||
stdout = b'''
|
||||
Scanning 615 folders for symlinks in /home/nvbn/work/zcho/BookkaWebView/node_modules (6ms)
|
||||
|
||||
Commands:
|
||||
- start: starts the webserver
|
||||
- bundle: builds the javascript bundle for offline use
|
||||
- unbundle: builds javascript as "unbundle" for offline use
|
||||
- new-library: generates a native library bridge
|
||||
- android: generates an Android project for your app
|
||||
- run-android: builds your app and starts it on a connected Android emulator or device
|
||||
- log-android: print Android logs
|
||||
- run-ios: builds your app and starts it on iOS simulator
|
||||
- log-ios: print iOS logs
|
||||
- upgrade: upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
|
||||
- link: link a library
|
||||
Usage: react-native [options] [command]
|
||||
|
||||
|
||||
Options:
|
||||
|
||||
-V, --version output the version number
|
||||
-h, --help output usage information
|
||||
|
||||
|
||||
Commands:
|
||||
|
||||
start [options] starts the webserver
|
||||
run-ios [options] builds your app and starts it on iOS simulator
|
||||
run-android [options] builds your app and starts it on a connected Android emulator or device
|
||||
new-library [options] generates a native library bridge
|
||||
bundle [options] builds the javascript bundle for offline use
|
||||
unbundle [options] builds javascript as "unbundle" for offline use
|
||||
eject [options] Re-create the iOS and Android folders and native code
|
||||
link [options] [packageName] links all native dependencies (updates native build files)
|
||||
unlink [options] <packageName> unlink native dependency
|
||||
install [options] <packageName> install and link native dependencies
|
||||
uninstall [options] <packageName> uninstall and unlink native dependencies
|
||||
upgrade [options] upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
|
||||
log-android [options] starts adb logcat
|
||||
log-ios [options] starts iOS device syslog tail
|
||||
'''
|
||||
|
||||
|
||||
@ -38,9 +52,12 @@ def test_not_match(command):
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, result', [
|
||||
(Command('react-native star', stdout, stderr('star')),
|
||||
(Command('react-native star', stderr=stderr('star')),
|
||||
'react-native start'),
|
||||
(Command('react-native logsandroid -f', stdout, stderr('logsandroid')),
|
||||
(Command('react-native logsandroid -f', stderr=stderr('logsandroid')),
|
||||
'react-native log-android -f')])
|
||||
def test_get_new_command(command, result):
|
||||
def test_get_new_command(mocker, command, result):
|
||||
patch = mocker.patch(
|
||||
'thefuck.rules.react_native_command_unrecognized.Popen')
|
||||
patch.return_value.stdout = BytesIO(stdout)
|
||||
assert get_new_command(command)[0] == result
|
||||
|
@ -1,14 +1,34 @@
|
||||
import re
|
||||
from thefuck.utils import for_app, replace_command
|
||||
from subprocess import Popen, PIPE
|
||||
from thefuck.utils import for_app, replace_command, cache, eager
|
||||
|
||||
|
||||
@for_app('react-native')
|
||||
def match(command):
|
||||
return re.match(r'Command `.*` unrecognized', command.stderr)
|
||||
return re.findall(r"Unrecognized command '.*'", command.stderr)
|
||||
|
||||
|
||||
@cache('package.json')
|
||||
@eager
|
||||
def _get_commands():
|
||||
proc = Popen(['react-native', '--help'], stdout=PIPE)
|
||||
should_yield = False
|
||||
for line in proc.stdout.readlines():
|
||||
line = line.decode().strip()
|
||||
|
||||
if not line:
|
||||
continue
|
||||
|
||||
if 'Commands:' in line:
|
||||
should_yield = True
|
||||
continue
|
||||
|
||||
if should_yield:
|
||||
yield line.split(' ')[0]
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
misspelled_command = re.findall(r'Command `(.*)` unrecognized',
|
||||
misspelled_command = re.findall(r"Unrecognized command '(.*)'",
|
||||
command.stderr)[0]
|
||||
commands = re.findall(r' - (.*): .*\n', command.stdout)
|
||||
commands = _get_commands()
|
||||
return replace_command(command, misspelled_command, commands)
|
||||
|
Loading…
x
Reference in New Issue
Block a user