2012-07-11 05:27:37 +00:00
|
|
|
require "fileutils"
|
2012-04-19 20:59:48 +00:00
|
|
|
require 'optparse'
|
2013-01-28 21:06:13 +00:00
|
|
|
require "pathname"
|
2012-04-19 20:59:48 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandBox
|
|
|
|
module Command
|
2012-11-07 05:05:14 +00:00
|
|
|
class Repackage < Vagrant.plugin("2", :command)
|
2012-04-19 20:59:48 +00:00
|
|
|
def execute
|
2013-01-28 21:06:13 +00:00
|
|
|
opts = OptionParser.new do |o|
|
2014-04-13 00:57:51 +00:00
|
|
|
o.banner = "Usage: vagrant box repackage <name> <provider> <version>"
|
2012-04-19 20:59:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
2014-05-22 16:35:12 +00:00
|
|
|
raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp if argv.length != 3
|
2012-04-19 20:59:48 +00:00
|
|
|
|
2012-07-11 05:27:37 +00:00
|
|
|
box_name = argv[0]
|
|
|
|
box_provider = argv[1].to_sym
|
2014-04-13 00:57:51 +00:00
|
|
|
box_version = argv[2]
|
2012-07-11 05:27:37 +00:00
|
|
|
|
|
|
|
# Verify the box exists that we want to repackage
|
2014-04-13 00:57:51 +00:00
|
|
|
box = @env.boxes.find(box_name, box_provider, "= #{box_version}")
|
|
|
|
if !box
|
2014-04-13 01:00:33 +00:00
|
|
|
raise Vagrant::Errors::BoxNotFoundWithProviderAndVersion,
|
|
|
|
name: box_name,
|
|
|
|
provider: box_provider.to_s,
|
|
|
|
version: box_version
|
2012-07-11 06:06:26 +00:00
|
|
|
end
|
|
|
|
|
2012-07-11 05:27:37 +00:00
|
|
|
# Repackage the box
|
2014-02-07 04:22:15 +00:00
|
|
|
output_name = @env.vagrantfile.config.package.name || "package.box"
|
2014-02-05 23:35:37 +00:00
|
|
|
output_path = Pathname.new(File.expand_path(output_name, FileUtils.pwd))
|
2012-07-11 05:27:37 +00:00
|
|
|
box.repackage(output_path)
|
2012-04-19 20:59:48 +00:00
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|