Sha256: 476dc1ff153cc2c00e7a7557cfdc2cd011e997039a3846e85b5c1343b5483d36

Contents?: true

Size: 977 Bytes

Versions: 4

Compression:

Stored size: 977 Bytes

Contents

# frozen_string_literal: true
module Bundler
  class CLI::Init
    attr_reader :options
    def initialize(options)
      @options = options
    end

    def run
      if File.exist?("Gemfile")
        Bundler.ui.error "Gemfile already exists at #{SharedHelpers.pwd}/Gemfile"
        exit 1
      end

      if options[:gemspec]
        gemspec = File.expand_path(options[:gemspec])
        unless File.exist?(gemspec)
          Bundler.ui.error "Gem specification #{gemspec} doesn't exist"
          exit 1
        end

        spec = Bundler.load_gemspec_uncached(gemspec)

        puts "Writing new Gemfile to #{SharedHelpers.pwd}/Gemfile"
        File.open("Gemfile", "wb") do |file|
          file << "# Generated from #{gemspec}\n"
          file << spec.to_gemfile
        end
      else
        puts "Writing new Gemfile to #{SharedHelpers.pwd}/Gemfile"
        FileUtils.cp(File.expand_path("../../templates/Gemfile", __FILE__), "Gemfile")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bundler-1.15.4 lib/bundler/cli/init.rb
bundler-1.15.3 lib/bundler/cli/init.rb
bundler-1.15.2 lib/bundler/cli/init.rb
bundler-1.15.1 lib/bundler/cli/init.rb