1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 06:38:32 +00:00

Merge pull request #15 from Comp-490-TR-Afternoon-Group-Four/#1-add-rvm-use-support

#1 add rvm use support
This commit is contained in:
Ryan Callahan 2021-04-16 17:52:46 -04:00 committed by GitHub
commit df33844fc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View File

@ -307,6 +307,7 @@ following rules are enabled by default:
* `remove_shell_prompt_literal` – remove leading shell prompt symbol `$`, common when copying commands from documentations;
* `remove_trailing_cedilla` – remove trailing cedillas `ç`, a common typo for european keyboard layouts;
* `rm_dir` – adds `-rf` when you try to remove a directory;
* `rvm_use` – adds `rvm install` command infront of `rvm use` command when requested version is not installed;
* `scm_correction` – corrects wrong scm like `hg log` to `git log`;
* `sed_unterminated_s` – adds missing '/' to `sed`'s `s` commands;
* `sl_ls` – changes `sl` to `ls`;

View File

@ -0,0 +1,26 @@
import pytest
from thefuck.rules.rvm_use import match, get_new_command
from thefuck.types import Command
output = pattern = """RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example."""
@pytest.mark.parametrize('command', [
Command('rvm use 2.7.2', output),
Command('rvm use 3.0.1', output),
Command('rvm use 1.6.7', output)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('rvm use 2.7.2', output), 'rvm install "ruby-2.7.2" && rvm use 2.7.2'),
(Command('rvm use 3.0.1', output), 'rvm install "ruby-3.0.1" && rvm use 3.0.1'),
(Command('rvm use 1.6.7', output), 'rvm install "ruby-1.6.7" && rvm use 1.6.7')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command

19
thefuck/rules/rvm_use.py Normal file
View File

@ -0,0 +1,19 @@
from thefuck.utils import for_app
from thefuck.shells import shell
@for_app('rvm', at_least=2)
def match(command):
args = command.script_parts
pattern = """RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example."""
return args[1] == 'use' and pattern in command.output
def get_new_command(command):
args = command.script_parts
return shell.and_('rvm install \"ruby-{}\"'.format(args[2]), 'rvm use {}'.format(args[2]))