Sha256: 3feb03c8a07784d0037ca9b6999606b0cfaf3e34eda0a9f0943a8a4b84738bd4

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

module Vagrant
  class Commands
    class Init < Base
      Base.subcommand "init", self
      description "Initializes current folder for Vagrant usage"

      def execute(args)
        create_vagrantfile(:default_box => args[0] , :default_box_url => args[1])
      end

      def options_spec(opts)
        opts.banner = "Usage: vagrant init [name] [box_url]"
      end

      # Actually writes the initial Vagrantfile to the current working directory.
      # The Vagrantfile will contain the base box configuration specified, or
      # will just use "base" if none is specified.
      #
      # @param [String] :default_box The default base box for this
      # Vagrantfile
      # @param [String] :default_box_url The default url for fetching
      # the given box for the Vagrantfile
      def create_vagrantfile(opts={})
        rootfile_path = File.join(Dir.pwd, Environment::ROOTFILE_NAME)
        error_and_exit(:rootfile_already_exists) if File.exist?(rootfile_path)

        # Set the defaults of the Vagrantfile
        opts[:default_box] ||= "base"

        File.open(rootfile_path, 'w+') do |f|
          f.write(TemplateRenderer.render(Environment::ROOTFILE_NAME, opts))
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrantup-0.5.4 lib/vagrant/commands/init.rb
vagrantup-0.5.3 lib/vagrant/commands/init.rb
vagrantup-0.5.2 lib/vagrant/commands/init.rb
vagrant-0.5.4 lib/vagrant/commands/init.rb
vagrant-0.5.3 lib/vagrant/commands/init.rb
vagrant-0.5.2 lib/vagrant/commands/init.rb