Skip to content

Commit

Permalink
Merge 336d8b7 into abbbd1f
Browse files Browse the repository at this point in the history
  • Loading branch information
mlk committed Aug 20, 2015
2 parents abbbd1f + 336d8b7 commit 2d5ca19
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `tsuru_not_command` – fixes wrong `tsuru` commands like `tsuru shell`;
* `tmux` – fixes `tmux` commands;
* `unknown_command` – fixes hadoop hdfs-style "unknown command" for example adds missing '-' to the command on `hdfs dfs ls`;
* `vagrant_up` – starts up the vagrant instance;
* `whois` – fixes `whois` command.

Enabled by default only on specific platforms:
Expand Down
35 changes: 35 additions & 0 deletions tests/rules/test_vagrant_up.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
from thefuck.rules.vagrant_up import match, get_new_command
from tests.utils import Command


@pytest.mark.parametrize('command', [
Command(script='vagrant ssh', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'),
Command(script='vagrant ssh devbox', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'),
Command(script='vagrant rdp',
stderr='VM must be created before running this command. Run `vagrant up` first.'),
Command(script='vagrant rdp devbox',
stderr='VM must be created before running this command. Run `vagrant up` first.')])
def test_match(command):
assert match(command, None)


@pytest.mark.parametrize('command', [
Command(script='vagrant ssh', stderr=''),
Command(script='vagrant ssh jeff', stderr='The machine with the name \'jeff\' was not found configured for this Vagrant environment.'),
Command(script='vagrant ssh', stderr='A Vagrant environment or target machine is required to run this command. Run `vagrant init` to create a new Vagrant environment. Or, get an ID of a target machine from `vagrant global-status` to run this command on. A final option is to change to a directory with a Vagrantfile and to try again.'),
Command()])
def test_not_match(command):
assert not match(command, None)


@pytest.mark.parametrize('command, new_command', [
(Command(script='vagrant ssh', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'), 'vagrant up && vagrant ssh'),
(Command(script='vagrant ssh devbox', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'), ['vagrant up devbox && vagrant ssh devbox', 'vagrant up && vagrant ssh devbox']),
(Command(script='vagrant rdp',
stderr='VM must be created before running this command. Run `vagrant up` first.'), 'vagrant up && vagrant rdp'),
(Command(script='vagrant rdp devbox',
stderr='VM must be created before running this command. Run `vagrant up` first.'), ['vagrant up devbox && vagrant rdp devbox', 'vagrant up && vagrant rdp devbox'])])
def test_get_new_command(command, new_command):
assert get_new_command(command, None) == new_command

18 changes: 18 additions & 0 deletions thefuck/rules/vagrant_up.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from thefuck import shells


def match(command, settings):
return command.script.startswith('vagrant ') and 'run `vagrant up`' in command.stderr.lower()


def get_new_command(command, settings):
cmds = command.script.split(' ')
machine = None
if len(cmds) >= 3:
machine = cmds[2]

startAllInstances = shells.and_("vagrant up", command.script)
if machine is None:
return startAllInstances
else:
return [ shells.and_("vagrant up " + machine, command.script), startAllInstances]

0 comments on commit 2d5ca19

Please sign in to comment.