From d86884699e07a91d73f2b7ea50378475b907cf9b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 24 Aug 2010 23:46:10 -0700 Subject: [PATCH] `vagrant ssh` and update CHANGELOG before I forget --- CHANGELOG.md | 8 +++++++- lib/vagrant/command/ssh.rb | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 lib/vagrant/command/ssh.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ad03ab36..4282bed69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ ## 0.6.0 (unreleased) - + - Converted CLI to use Thor. As a tradeoff, there are some backwards + incompatibilities: + * `vagrant package` - The `--include` flag now separates filenames + by spaces, instead of by commas. e.g. `vagrant package --include x y z` + * `vagrant ssh` - If you specify a command to execute using the `--execute` + flag, you may now only specify one command (before you were able to + specify an arbitrary amount). e.g. `vagrant ssh -e "echo hello"` ## 0.5.3 (August 23, 2010) diff --git a/lib/vagrant/command/ssh.rb b/lib/vagrant/command/ssh.rb new file mode 100644 index 000000000..b8b1f2303 --- /dev/null +++ b/lib/vagrant/command/ssh.rb @@ -0,0 +1,42 @@ +module Vagrant + module Command + class SSHCommand < Base + desc "SSH into the currently running Vagrant environment." + class_option :execute, :type => :string, :default => false, :aliases => "-e" + register "ssh" + + def execute + if options[:execute] + ssh_execute + else + ssh_connect + end + end + + protected + + def ssh_execute + ssh_vm.ssh.execute do |ssh| + ssh_vm.env.ui.info "Execute: #{options[:execute]}" + ssh.exec!(options[:execute]) do |channel, type, data| + ssh_vm.env.ui.info "#{data}" + end + end + end + + def ssh_connect + raise VMNotCreatedError.new("The VM must be created for SSH to work. Please run `vagrant up`.") if !ssh_vm.created? + ssh_vm.ssh.connect + end + + def ssh_vm + @ssh_vm ||= begin + vm = self.name.nil? && env.multivm? ? env.primary_vm + raise MultiVMTargetRequired.new("A target or primary VM must be specified for SSH in a multi-vm environment.") if !vm && target_vms.length > 1 + vm = target_vms.first if !vm + vm + end + end + end + end +end