`vagrant plugin license` command.

This commit is contained in:
Mitchell Hashimoto 2013-02-04 10:22:15 -08:00
parent 7e71b73e4a
commit 55c905b43b
6 changed files with 116 additions and 0 deletions

View File

@ -299,6 +299,10 @@ module Vagrant
error_key(:plugin_install_bad_entry_point)
end
class PluginInstallLicenseNotFound < VagrantError
error_key(:plugin_install_license_not_found)
end
class PluginInstallNotFound < VagrantError
error_key(:plugin_install_not_found)
end
@ -311,6 +315,10 @@ module Vagrant
error_key(:plugin_load_failed)
end
class PluginNotFound < VagrantError
error_key(:plugin_not_found)
end
class SCPPermissionDenied < VagrantError
error_key(:scp_permission_denied)
end

View File

@ -14,6 +14,14 @@ module VagrantPlugins
end
end
# This middleware sequence licenses paid addons.
def self.action_license
Vagrant::Action::Builder.new.tap do |b|
b.use BundlerCheck
b.use LicensePlugin
end
end
# This middleware sequence will list all installed plugins.
def self.action_list
Vagrant::Action::Builder.new.tap do |b|

View File

@ -0,0 +1,53 @@
require "fileutils"
require "pathname"
require "rubygems"
require "set"
require "log4r"
module VagrantPlugins
module CommandPlugin
module Action
# This middleware licenses a plugin by copying the license file to
# the proper place.
class LicensePlugin
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::plugins::plugincommand::license")
end
def call(env)
# Get the list of installed plugins according to the state file
installed = Set.new(env[:plugin_state_file].installed_plugins)
# If the plugin we're trying to license doesn't exist in the
# state file, then it is an error.
if !installed.include?(env[:plugin_name])
raise Vagrant::Errors::PluginNotFound, :name => env[:plugin_name]
end
# Verify the license file exists
license_file = Pathname.new(env[:plugin_license_path])
if !license_file.file?
raise Vagrant::Errors::PluginInstallLicenseNotFound,
:name => env[:plugin_name],
:path => license_file.to_s
end
# Copy it in.
final_path = env[:home_path].join("license-#{env[:plugin_name]}.lic")
@logger.info("Copying license from: #{license_file}")
@logger.info("Copying license to: #{final_path}")
env[:ui].info(I18n.t("vagrant.commands.plugin.installing_license",
:name => env[:plugin_name]))
FileUtils.cp(license_file, final_path)
# Installed!
env[:ui].success(I18n.t("vagrant.commands.plugin.installed_license"))
@app.call(env)
end
end
end
end
end

View File

@ -0,0 +1,31 @@
require 'optparse'
require_relative "base"
module VagrantPlugins
module CommandPlugin
module Command
class License < Base
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant plugin license <name> <license-file> [-h]"
end
# Parse the options
argv = parse_options(opts)
return if !argv
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2
# License the plugin
action(Action.action_license, {
:plugin_license_path => argv[1],
:plugin_name => argv[0]
})
# Success, exit status 0
0
end
end
end
end
end

View File

@ -15,6 +15,11 @@ module VagrantPlugins
Install
end
@subcommands.register(:license) do
require_relative "license"
License
end
@subcommands.register(:list) do
require_relative "list"
List

View File

@ -175,6 +175,10 @@ en:
the entry point doesn't exist. The entry point attempted was
'%{entry_point}'. If this is not correct, please manually
specify an `--entry-point` when installing the plugin.
plugin_install_license_not_found: |-
The license file to install could not be found. Please verify
the path you gave is correct. The path to the license file given
was: '%{path}'
plugin_install_not_found: |-
The plugin '%{name}' could not be found in local or remote
repositories. Please check the name of the plugin and try again.
@ -183,6 +187,9 @@ en:
properly installed via `vagrant plugin`.
plugin_load_failed: |-
Failed to load the "%{plugin}" plugin. View logs for more details.
plugin_not_found: |-
The plugin '%{name}' could not be found. Please install this plugin
prior to attempting to do anything with it.
port_collision_resume: |-
This VM cannot be resumed, because the forwarded ports would collide with
another running virtual machine. Normally, Vagrant will attempt to fix this
@ -420,6 +427,10 @@ en:
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
plugin:
installed_license: |-
The license for '%{name}' was successfully installed!
installing_license: |-
Installing license for '%{name}'...
no_plugins: |-
No plugins installed.
installed: |-