Merge pull request #1461 from hmalphettes/master

Ability to install a vagrant plugin with a specific version and source
This commit is contained in:
Mitchell Hashimoto 2013-03-20 22:28:30 -07:00
commit 3fe7809eea
2 changed files with 27 additions and 3 deletions

View File

@ -16,15 +16,23 @@ module VagrantPlugins
def call(env)
plugin_name = env[:plugin_name]
prerelease = env[:plugin_prerelease]
version = env[:plugin_version]
# Install the gem
plugin_name_label = plugin_name
plugin_name_label += ' --prerelease' if prerelease
plugin_name_label += " --version \"#{version}\"" if version
env[:ui].info(I18n.t("vagrant.commands.plugin.installing",
:name => plugin_name))
:name => plugin_name_label))
installed_gems = env[:gem_helper].with_environment do
installer = Gem::DependencyInstaller.new(:document => [])
# Override the list of sources by the ones set on the cmd-line if any
Gem.sources = env[:plugin_sources] if env[:plugin_sources]
installer = Gem::DependencyInstaller.new(:document => [], :prerelease => prerelease)
begin
installer.install(plugin_name)
installer.install(plugin_name, version)
rescue Gem::GemNotFoundException
raise Vagrant::Errors::PluginInstallNotFound,
:name => plugin_name

View File

@ -17,6 +17,19 @@ module VagrantPlugins
"The name of the entry point file for loading the plugin.") do |entry_point|
options[:entry_point] = entry_point
end
o.on("--plugin-prerelease",
"Install a prereleased version of the plugin") do |plugin_prerelease|
options[:plugin_prerelease] = plugin_prerelease
end
o.on("--plugin-version PLUGIN_VERSION", String,
"Install a specific version of the plugin") do |plugin_version|
options[:plugin_version] = plugin_version
end
o.on("--plugin-source PLUGIN_SOURCE", String,
"Add a ruby gem repository") do |plugin_source|
options[:plugin_sources] = [] if !options[:plugin_sources]
options[:plugin_sources] << plugin_source
end
end
# Parse the options
@ -27,6 +40,9 @@ module VagrantPlugins
# Install the gem
action(Action.action_install, {
:plugin_entry_point => options[:entry_point],
:plugin_prerelease => options[:plugin_prerelease],
:plugin_version => options[:plugin_version],
:plugin_sources => options[:plugin_sources],
:plugin_name => argv[0]
})