diff --git a/plugins/commands/plugin/command/base.rb b/plugins/commands/plugin/command/base.rb new file mode 100644 index 000000000..7c98b38b6 --- /dev/null +++ b/plugins/commands/plugin/command/base.rb @@ -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 diff --git a/plugins/commands/plugin/command/install.rb b/plugins/commands/plugin/command/install.rb index dc5b2fa6b..295285cc2 100644 --- a/plugins/commands/plugin/command/install.rb +++ b/plugins/commands/plugin/command/install.rb @@ -1,9 +1,11 @@ require 'optparse' +require_relative "base" + module VagrantPlugins module CommandPlugin module Command - class Install < Vagrant.plugin("2", :command) + class Install < Base def execute opts = OptionParser.new do |o| o.banner = "Usage: vagrant plugin install [-h]" @@ -15,11 +17,7 @@ module VagrantPlugins raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1 # Install the gem - @env.action_runner.run(Action.action_install, { - :gem_helper => GemHelper.new(@env.gems_path), - :plugin_name => argv[0], - :plugin_state_file => StateFile.new(@env.data_dir.join("plugins.json")) - }) + action(Action.action_install, :plugin_name => argv[0]) # Success, exit status 0 0 diff --git a/plugins/commands/plugin/command/list.rb b/plugins/commands/plugin/command/list.rb new file mode 100644 index 000000000..61027c216 --- /dev/null +++ b/plugins/commands/plugin/command/list.rb @@ -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 diff --git a/plugins/commands/plugin/command/root.rb b/plugins/commands/plugin/command/root.rb index d2fc4b059..3b1d29aa5 100644 --- a/plugins/commands/plugin/command/root.rb +++ b/plugins/commands/plugin/command/root.rb @@ -14,6 +14,11 @@ module VagrantPlugins require_relative "install" Install end + + @subcommands.register(:list) do + require_relative "list" + List + end end def execute