2012-04-19 20:59:48 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandBox
|
|
|
|
module Command
|
2012-06-26 23:18:02 +00:00
|
|
|
class Add < Vagrant.plugin("1", :command)
|
2012-04-19 20:59:48 +00:00
|
|
|
def execute
|
|
|
|
options = {}
|
|
|
|
|
2012-08-18 23:13:14 +00:00
|
|
|
opts = OptionParser.new do |o|
|
|
|
|
o.banner = "Usage: vagrant box add <name> <url>"
|
|
|
|
o.separator ""
|
2012-04-19 20:59:48 +00:00
|
|
|
|
2012-08-18 23:13:14 +00:00
|
|
|
o.on("-f", "--force", "Overwrite an existing box if it exists.") do |f|
|
2012-04-19 20:59:48 +00:00
|
|
|
options[:force] = f
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2
|
|
|
|
|
|
|
|
# If we're force adding, then be sure to destroy any existing box if it
|
|
|
|
# exists.
|
|
|
|
if options[:force]
|
2012-07-10 03:09:54 +00:00
|
|
|
existing = @env.boxes.find(argv[0], :virtualbox)
|
|
|
|
existing.destroy! if existing
|
2012-04-19 20:59:48 +00:00
|
|
|
end
|
|
|
|
|
2012-08-18 23:13:14 +00:00
|
|
|
@env.action_runner.run(Vagrant::Action.action_box_add, {
|
2012-07-10 03:09:54 +00:00
|
|
|
:box_name => argv[0],
|
|
|
|
:box_provider => :virtualbox,
|
|
|
|
:box_url => argv[1]
|
|
|
|
})
|
2012-04-19 20:59:48 +00:00
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|