Have a base class to invoke actions on the plugins
This commit is contained in:
parent
150cae86b7
commit
53667d44db
|
@ -0,0 +1,22 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module CommandPlugin
|
||||||
|
module Command
|
||||||
|
class Base < Vagrant.plugin("2", :command)
|
||||||
|
# This is a helper for executing an action sequence with the proper
|
||||||
|
# environment hash setup so that the plugin specific helpers are
|
||||||
|
# in.
|
||||||
|
#
|
||||||
|
# @param [Object] callable the Middleware callable
|
||||||
|
# @param [Hash] env Extra environment hash that is merged in.
|
||||||
|
def action(callable, env=nil)
|
||||||
|
env = {
|
||||||
|
:gem_helper => GemHelper.new(@env.gems_path),
|
||||||
|
:plugin_state_file => StateFile.new(@env.data_dir.join("plugins.json"))
|
||||||
|
}.merge(env || {})
|
||||||
|
|
||||||
|
@env.action_runner.run(callable, env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,9 +1,11 @@
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
|
require_relative "base"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module CommandPlugin
|
module CommandPlugin
|
||||||
module Command
|
module Command
|
||||||
class Install < Vagrant.plugin("2", :command)
|
class Install < Base
|
||||||
def execute
|
def execute
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
o.banner = "Usage: vagrant plugin install <name> [-h]"
|
o.banner = "Usage: vagrant plugin install <name> [-h]"
|
||||||
|
@ -15,11 +17,7 @@ module VagrantPlugins
|
||||||
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1
|
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1
|
||||||
|
|
||||||
# Install the gem
|
# Install the gem
|
||||||
@env.action_runner.run(Action.action_install, {
|
action(Action.action_install, :plugin_name => argv[0])
|
||||||
:gem_helper => GemHelper.new(@env.gems_path),
|
|
||||||
:plugin_name => argv[0],
|
|
||||||
:plugin_state_file => StateFile.new(@env.data_dir.join("plugins.json"))
|
|
||||||
})
|
|
||||||
|
|
||||||
# Success, exit status 0
|
# Success, exit status 0
|
||||||
0
|
0
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
require 'optparse'
|
||||||
|
|
||||||
|
require_relative "base"
|
||||||
|
|
||||||
|
module VagrantPlugins
|
||||||
|
module CommandPlugin
|
||||||
|
module Command
|
||||||
|
class List < Base
|
||||||
|
def execute
|
||||||
|
opts = OptionParser.new do |o|
|
||||||
|
o.banner = "Usage: vagrant plugin list [-h]"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Parse the options
|
||||||
|
argv = parse_options(opts)
|
||||||
|
return if !argv
|
||||||
|
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length > 0
|
||||||
|
|
||||||
|
# List the installed plugins
|
||||||
|
action(Action.action_list)
|
||||||
|
|
||||||
|
# Success, exit status 0
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -14,6 +14,11 @@ module VagrantPlugins
|
||||||
require_relative "install"
|
require_relative "install"
|
||||||
Install
|
Install
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@subcommands.register(:list) do
|
||||||
|
require_relative "list"
|
||||||
|
List
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
|
Loading…
Reference in New Issue