Class: Vagrant::Command::Init
Instance Method Summary collapse
Methods inherited from Base
Methods included from Util::SafePuts
Constructor Details
This class inherits a constructor from Vagrant::Command::Base
Instance Method Details
#execute ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant/command/init.rb', line 8 def execute = {} opts = OptionParser.new do |opts| opts. = "Usage: vagrant init [box-name] [box-url]" end # Parse the options argv = (opts) return if !argv save_path = @env.cwd.join("Vagrantfile") raise Errors::VagrantfileExistsError if save_path.exist? 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) # Success, exit status 0 0 end |