diff --git a/README.md b/README.md index d736c58..44720a5 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `python_command` – prepends `python` when you trying to run not executable/without `./` python script; * `python_execute` – appends missing `.py` when executing Python files; * `quotation_marks` – fixes uneven usage of `'` and `"` when containing args'; +* `react_native_command_unrecognized` – fixes unrecognized `react-native` commands; * `rm_dir` – adds `-rf` when you trying to remove directory; * `sed_unterminated_s` – adds missing '/' to `sed`'s `s` commands; * `sl_ls` – changes `sl` to `ls`; diff --git a/tests/rules/test_react_native_command_unrecognized.py b/tests/rules/test_react_native_command_unrecognized.py new file mode 100644 index 0000000..d010c68 --- /dev/null +++ b/tests/rules/test_react_native_command_unrecognized.py @@ -0,0 +1,46 @@ +import pytest +from thefuck.rules.react_native_command_unrecognized import match, \ + get_new_command +from tests.utils import Command + +stderr = 'Command `{}` unrecognized'.format + +stdout = ''' +Usage: react-native + +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 +''' + + +@pytest.mark.parametrize('command', [ + Command('react-native star', stderr=stderr('star')), + Command('react-native android-logs', stderr=stderr('android-logs'))]) +def test_match(command): + assert match(command) + + +@pytest.mark.parametrize('command', [ + Command('gradle star', stderr=stderr('star')), + Command('react-native start')]) +def test_not_match(command): + assert not match(command) + + +@pytest.mark.parametrize('command, result', [ + (Command('react-native star', stdout, stderr('star')), + 'react-native start'), + (Command('react-native logsandroid -f', stdout, stderr('logsandroid')), + 'react-native log-android -f')]) +def test_get_new_command(command, result): + assert get_new_command(command)[0] == result diff --git a/thefuck/const.py b/thefuck/const.py index 4ca546c..fdef9b3 100644 --- a/thefuck/const.py +++ b/thefuck/const.py @@ -32,7 +32,7 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES, 'history_limit': None, 'alter_history': True, 'wait_slow_command': 15, - 'slow_commands': ['lein'], + 'slow_commands': ['lein', 'react-native'], 'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}} ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', diff --git a/thefuck/rules/react_native_command_unrecognized.py b/thefuck/rules/react_native_command_unrecognized.py new file mode 100644 index 0000000..9ac1e2b --- /dev/null +++ b/thefuck/rules/react_native_command_unrecognized.py @@ -0,0 +1,14 @@ +import re +from thefuck.utils import for_app, replace_command + + +@for_app('react-native') +def match(command): + return re.match(r'Command `.*` unrecognized', command.stderr) + + +def get_new_command(command): + misspelled_command = re.findall(r'Command `(.*)` unrecognized', + command.stderr)[0] + commands = re.findall(r' - (.*): .*\n', command.stdout) + return replace_command(command, misspelled_command, commands)