2011-12-18 05:06:00 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
require 'vagrant/util/template_renderer'
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module CommandInit
|
2012-11-07 05:05:14 +00:00
|
|
|
class Command < Vagrant.plugin("2", :command)
|
2010-08-24 17:27:36 +00:00
|
|
|
def execute
|
2011-12-18 05:06:00 +00:00
|
|
|
options = {}
|
|
|
|
|
|
|
|
opts = OptionParser.new do |opts|
|
|
|
|
opts.banner = "Usage: vagrant init [box-name] [box-url]"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
|
|
|
save_path = @env.cwd.join("Vagrantfile")
|
2012-04-19 20:59:48 +00:00
|
|
|
raise Vagrant::Errors::VagrantfileExistsError if save_path.exist?
|
2011-12-18 05:06:00 +00:00
|
|
|
|
|
|
|
template_path = ::Vagrant.source_root.join("templates/commands/init/Vagrantfile")
|
|
|
|
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
|
|
|
:box_name => argv[0] || "base",
|
|
|
|
:box_url => argv[1])
|
|
|
|
|
|
|
|
# Write out the contents
|
|
|
|
save_path.open("w+") do |f|
|
|
|
|
f.write(contents)
|
|
|
|
end
|
|
|
|
|
|
|
|
@env.ui.info(I18n.t("vagrant.commands.init.success"),
|
|
|
|
:prefix => false)
|
2012-03-23 15:07:35 +00:00
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
0
|
|
|
|
end
|
2010-08-24 17:27:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|