2012-07-11 05:27:37 +00:00
|
|
|
require "fileutils"
|
2012-04-19 20:59:48 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
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
|
|
|
|
options = {}
|
|
|
|
|
|
|
|
opts = OptionParser.new do |opts|
|
2012-07-11 05:27:37 +00:00
|
|
|
opts.banner = "Usage: vagrant box repackage <name> <provider>"
|
2012-04-19 20:59:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
2012-07-11 05:27:37 +00:00
|
|
|
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2
|
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
|
|
|
|
|
|
|
|
# Verify the box exists that we want to repackage
|
2012-07-11 06:06:26 +00:00
|
|
|
box = nil
|
|
|
|
begin
|
|
|
|
box = @env.boxes.find(box_name, box_provider)
|
|
|
|
rescue Vagrant::Errors::BoxUpgradeRequired
|
|
|
|
@env.boxes.upgrade(box_name)
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
|
|
|
|
raise Vagrant::Errors::BoxNotFound, :name => box_name if !box
|
2012-07-11 05:27:37 +00:00
|
|
|
|
|
|
|
# Repackage the box
|
|
|
|
output_path = File.expand_path(@env.config.global.package.name, FileUtils.pwd)
|
|
|
|
box.repackage(output_path)
|
2012-04-19 20:59:48 +00:00
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|