vagrant/plugins/commands/box/command/repackage.rb

44 lines
1.3 KiB
Ruby
Raw Normal View History

2012-07-11 05:27:37 +00:00
require "fileutils"
2012-04-19 20:59:48 +00:00
require 'optparse'
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
opts = OptionParser.new do |o|
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
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
box_version = argv[2]
2012-07-11 05:27:37 +00:00
# Verify the box exists that we want to repackage
box = @env.boxes.find(box_name, box_provider, "= #{box_version}")
if !box
raise Vagrant::Errors::BoxNotFoundWithProviderAndVersion,
name: box_name,
provider: box_provider.to_s,
version: box_version
end
2012-07-11 05:27:37 +00:00
# Repackage the box
output_name = @env.vagrantfile.config.package.name || "package.box"
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