Sha256: 2a2145e7faf31c8c522ee23a80edb8184b60159334bd1762210d4e8a57309e34

Contents?: true

Size: 1.12 KB

Versions: 19

Compression:

Stored size: 1.12 KB

Contents

require 'optparse'

require 'vagrant/util/template_renderer'

module VagrantPlugins
  module CommandInit
    class Command < Vagrant.plugin("2", :command)
      def execute
        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")
        raise Vagrant::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
    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/plugins/commands/init/command.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/plugins/commands/init/command.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/plugins/commands/init/command.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/plugins/commands/init/command.rb
tnargav-1.3.6 plugins/commands/init/command.rb
tnargav-1.3.3 plugins/commands/init/command.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/commands/init/command.rb
tnargav-1.2.3 plugins/commands/init/command.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/commands/init/command.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/plugins/commands/init/command.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/plugins/commands/init/command.rb
tnargav-1.2.2 plugins/commands/init/command.rb
vagrantup-1.1.3 plugins/commands/init/command.rb
vagrantup-1.1.2 plugins/commands/init/command.rb
vagrantup-1.1.1 plugins/commands/init/command.rb
vagrantup-1.1.0 plugins/commands/init/command.rb
vagrantup-1.1.4 plugins/commands/init/command.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/plugins/commands/init/command.rb
vagrant-lxc-0.0.1 vendor/vagrant/plugins/commands/init/command.rb