diff --git a/plugins/commands/box/command/add.rb b/plugins/commands/box/command/add.rb index 73511ea99..403dddb79 100644 --- a/plugins/commands/box/command/add.rb +++ b/plugins/commands/box/command/add.rb @@ -1,9 +1,11 @@ require 'optparse' +require_relative "base" + module VagrantPlugins module CommandBox module Command - class Add < Vagrant.plugin("2", :command) + class Add < Base def execute options = {} @@ -34,13 +36,12 @@ module VagrantPlugins provider = nil provider = options[:provider].to_sym if options[:provider] - @env.action_runner.run(Vagrant::Action.action_box_add, { + action(Vagrant::Action.action_box_add, { :box_name => argv[0], :box_provider => provider, :box_url => argv[1], :box_force => options[:force], - :box_download_insecure => options[:insecure], - :box_state_file => StateFile.new(@env.home_path.join('boxes.json')) + :box_download_insecure => options[:insecure] }) # Success, exit status 0 diff --git a/plugins/commands/box/command/base.rb b/plugins/commands/box/command/base.rb new file mode 100644 index 000000000..b80b2dcb7 --- /dev/null +++ b/plugins/commands/box/command/base.rb @@ -0,0 +1,21 @@ +module VagrantPlugins + module CommandBox + 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 = { + :box_state_file => StateFile.new(@env.home_path.join("boxes.json")) + }.merge(env || {}) + + @env.action_runner.run(callable, env) + end + end + end + end +end diff --git a/plugins/commands/box/command/remove.rb b/plugins/commands/box/command/remove.rb index bea7dd83b..6b52f023f 100644 --- a/plugins/commands/box/command/remove.rb +++ b/plugins/commands/box/command/remove.rb @@ -1,9 +1,11 @@ require 'optparse' +require_relative "base" + module VagrantPlugins module CommandBox module Command - class Remove < Vagrant.plugin("2", :command) + class Remove < Base def execute opts = OptionParser.new do |o| o.banner = "Usage: vagrant box remove " @@ -34,10 +36,9 @@ module VagrantPlugins argv[1] = providers[0] || "" end - @env.action_runner.run(Vagrant::Action.action_box_remove, { + action(Vagrant::Action.action_box_remove, { :box_name => argv[0], - :box_provider => argv[1], - :box_state_file => StateFile.new(@env.home_path.join('boxes.json')) + :box_provider => argv[1] }) # Success, exit status 0