`vagrant box repackage` can now take the typical `--output` and `--include` parameters

This commit is contained in:
Mitchell Hashimoto 2010-07-28 20:30:16 -07:00
parent 836b539399
commit fcf1116f27
5 changed files with 42 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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")

View File

@ -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