lib/bundler/cli.rb in bundler-0.9.13 vs lib/bundler/cli.rb in bundler-0.9.14

- old
+ new

@@ -8,13 +8,30 @@ module Bundler class CLI < Thor check_unknown_options! unless ARGV.include?("exec") desc "init", "Generates a Gemfile into the current working directory" + method_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile" def init + opts = options.dup if File.exist?("Gemfile") - puts "Gemfile already exists at #{Dir.pwd}/Gemfile" + Bundler.ui.error "Gemfile already exists at #{Dir.pwd}/Gemfile" + exit 1 + end + + if opts[:gemspec] + gemspec = File.expand_path(opts[:gemspec]) + unless File.exist?(gemspec) + Bundler.ui.error "Gem specification #{gemspec} doesn't exist" + exit 1 + end + spec = Gem::Specification.load(gemspec) + puts "Writing new Gemfile to #{Dir.pwd}/Gemfile" + File.open('Gemfile', 'w') do |file| + file << "# Generated from #{gemspec}\n" + file << spec.to_gemfile + end else puts "Writing new Gemfile to #{Dir.pwd}/Gemfile" FileUtils.cp(File.expand_path('../templates/Gemfile', __FILE__), 'Gemfile') end end @@ -109,14 +126,15 @@ Bundler.ui.info locate_gem(gem_name) else environment = Bundler.load Bundler.ui.info "Gems included by the bundle:" environment.specs.sort_by { |s| s.name }.each do |s| - Bundler.ui.info " * #{s.name} (#{s.version})" + Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})" end end end + map %w(list) => "show" desc "cache", "Cache all the gems to vendor/cache" def cache environment = Bundler.load environment.cache @@ -160,13 +178,17 @@ Kernel.exec *ARGV end desc "open GEM", "Opens the source directory of the given bundled gem" def open(name) - editor = ENV['EDITOR'] - return Bundler.ui.info("To open a bundled gem, set $EDITOR") if editor.nil? || editor.empty? - command = "#{editor} #{locate_gem(name)}" - Bundler.ui.info "Could not run '#{command}'" unless system(command) + editor = [ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? } + if editor + command = "#{editor} #{locate_gem(name)}" + success = system(command) + Bundler.ui.info "Could not run '#{command}'" unless success + else + Bundler.ui.info("To open a bundled gem, set $EDITOR") + end end desc "version", "Prints the bundler's version information" def version Bundler.ui.info "Bundler version #{Bundler::VERSION}"