diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb index fcaf4a2a0..9035a2874 100644 --- a/lib/vagrant/box.rb +++ b/lib/vagrant/box.rb @@ -138,8 +138,8 @@ module Vagrant end # Begins sequence to repackage this box. - def repackage - env.actions.run(:box_repackage, { "box" => self }) + def repackage(options=nil) + env.actions.run(:box_repackage, { "box" => self }.merge(options || {})) end # Returns the directory to the location of this boxes content in the local diff --git a/lib/vagrant/commands/box/repackage.rb b/lib/vagrant/commands/box/repackage.rb index 7baeeed38..eda1ae1b6 100644 --- a/lib/vagrant/commands/box/repackage.rb +++ b/lib/vagrant/commands/box/repackage.rb @@ -7,15 +7,27 @@ module Vagrant description "Repackages a box which has already been added." def execute(args=[]) + args = parse_options(args) return show_help if args.length != 1 box = Vagrant::Box.find(env, args.first) return error_and_exit(:box_repackage_doesnt_exist) if box.nil? - box.repackage + box.repackage(options) end def options_spec(opts) - opts.banner = "Usage: vagrant box repackage NAME" + opts.banner = "Usage: vagrant box repackage NAME [--output FILENAME] [--include FILES]" + + options["package.output"] = nil + options["package.include"] = [] + + opts.on("--include x,y,z", Array, "List of files to include in the package") do |v| + options["package.include"] = v + end + + opts.on("-o", "--output FILE", "File to save the package as.") do |v| + options["package.output"] = v + end end end end diff --git a/lib/vagrant/commands/package.rb b/lib/vagrant/commands/package.rb index 5ecf1fb15..05d373a98 100644 --- a/lib/vagrant/commands/package.rb +++ b/lib/vagrant/commands/package.rb @@ -57,7 +57,7 @@ module Vagrant end def options_spec(opts) - opts.banner = "Usage: vagrant package [--base BASE] [--include FILES]" + opts.banner = "Usage: vagrant package [--base BASE] [--output FILENAME] [--include FILES]" # Defaults options[:base] = nil diff --git a/test/vagrant/box_test.rb b/test/vagrant/box_test.rb index 8117e4f14..e30b43885 100644 --- a/test/vagrant/box_test.rb +++ b/test/vagrant/box_test.rb @@ -139,6 +139,18 @@ class BoxTest < Test::Unit::TestCase end end + context "repackaging" do + should "execute the repackage action" do + @box.env.actions.expects(:run).with(:box_repackage, { "box" => @box }) + @box.repackage + end + + should "forward given options into the action" do + @box.env.actions.expects(:run).with(:box_repackage, { "box" => @box, "foo" => "bar" }) + @box.repackage("foo" => "bar") + end + end + context "ovf file" do setup do @box.stubs(:directory).returns("foo") diff --git a/test/vagrant/commands/box/repackage_test.rb b/test/vagrant/commands/box/repackage_test.rb index d10744732..2af394ac1 100644 --- a/test/vagrant/commands/box/repackage_test.rb +++ b/test/vagrant/commands/box/repackage_test.rb @@ -22,7 +22,7 @@ class CommandsBoxRepackageTest < Test::Unit::TestCase should "show help if not enough arguments" do Vagrant::Box.expects(:find).never @instance.expects(:show_help).once - @instance.execute([]) + @instance.execute(["--include", "x,y,z"]) end should "error and exit if the box doesn't exist" do @@ -31,11 +31,22 @@ class CommandsBoxRepackageTest < Test::Unit::TestCase @instance.execute([@name]) end - should "call destroy on the box if it exists" do + should "call repackage on the box if it exists" do @box = mock("box") Vagrant::Box.expects(:find).with(@env, @name).returns(@box) @box.expects(:repackage).once @instance.execute([@name]) end + + should "pass given options into repackage" do + @box = mock("box") + Vagrant::Box.expects(:find).with(@env, @name).returns(@box) + @box.expects(:repackage).once.with() do |opts| + assert opts.is_a?(Hash) + assert_equal "filename.box", opts["package.output"] + true + end + @instance.execute([@name, "--output", "filename.box"]) + end end end