`vagrant ssh_config`

This commit is contained in:
Mitchell Hashimoto 2010-08-24 23:55:53 -07:00
parent 3da5fc87a3
commit 23526c3746
4 changed files with 26 additions and 1 deletions

View File

@ -7,6 +7,8 @@
* `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"`
* `vagrant ssh-config` has become `vagrant ssh_config` due to a limitation
in Thor.
## 0.5.3 (August 23, 2010)

View File

@ -36,7 +36,7 @@ module Vagrant
# Extracts the name of the command from a usage string. Example:
# `init [box_name] [box_url]` becomes just `init`.
def self.extract_name_from_usage(usage)
/^([a-zA-Z0-9]+)(\s+(.+?))?$/.match(usage).to_a[1]
/^([-_a-zA-Z0-9]+)(\s+(.+?))?$/.match(usage).to_a[1]
end
def initialize(args=[], options={}, config={})

View File

@ -0,0 +1,22 @@
module Vagrant
module Command
class SSHConfigCommand < NamedBase
desc "outputs .ssh/config valid syntax for connecting to this environment via ssh"
class_option :host, :type => :string, :default => nil, :aliases => "-h"
register "ssh_config"
def execute
raise MultiVMTargetRequired.new("Please specify a single VM to get SSH config info.") if target_vms.length > 1
vm = target_vms.first
raise VMNotCreatedError.new("The VM must be created to get the SSH info.") if !vm.created?
env.ui.info Util::TemplateRenderer.render("ssh_config", {
:host_key => options[:host] || "vagrant",
:ssh_user => vm.env.config.ssh.username,
:ssh_port => vm.ssh.port,
:private_key_path => vm.env.config.ssh.private_key_path
})
end
end
end
end

View File

@ -10,6 +10,7 @@ class CommandBaseTest < Test::Unit::TestCase
should "extract properly" do
assert_equal "init", @klass.extract_name_from_usage("init")
assert_equal "init", @klass.extract_name_from_usage("init [foo] [bar]")
assert_equal "ssh-config", @klass.extract_name_from_usage("ssh-config")
end
end