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 Add < Vagrant.plugin("2", :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|
|
2013-01-12 05:24:57 +00:00
|
|
|
o.banner = "Usage: vagrant box add <name> <url> [--provider provider] [-h]"
|
2012-08-18 23:13:14 +00:00
|
|
|
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
|
2013-01-12 05:24:57 +00:00
|
|
|
|
2013-04-03 18:57:40 +00:00
|
|
|
o.on("--insecure", "If set, SSL certs will not be validated.") do |i|
|
|
|
|
options[:insecure] = i
|
|
|
|
end
|
|
|
|
|
2013-01-12 05:24:57 +00:00
|
|
|
o.on("--provider provider", String,
|
|
|
|
"The provider that backs the box.") do |p|
|
|
|
|
options[:provider] = p
|
|
|
|
end
|
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 < 2
|
|
|
|
|
2013-01-17 06:52:44 +00:00
|
|
|
# Get the provider if one was set
|
|
|
|
provider = nil
|
|
|
|
provider = options[:provider].to_sym if options[:provider]
|
|
|
|
|
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],
|
2013-01-17 06:52:44 +00:00
|
|
|
:box_provider => provider,
|
2013-03-14 04:19:59 +00:00
|
|
|
:box_url => argv[1],
|
2013-04-03 18:57:40 +00:00
|
|
|
:box_force => options[:force],
|
|
|
|
:box_download_insecure => options[:insecure],
|
2012-07-10 03:09:54 +00:00
|
|
|
})
|
2012-04-19 20:59:48 +00:00
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|