lib/bundler/cli.rb in bundler-1.5.3 vs lib/bundler/cli.rb in bundler-1.6.0.pre.1
- old
+ new
@@ -1,7 +1,6 @@
require 'bundler'
-require 'bundler/similarity_detector'
require 'bundler/vendored_thor'
module Bundler
class CLI < Thor
include Thor::Actions
@@ -300,24 +299,33 @@
"Only output warnings and errors."
method_option "full-index", :type => :boolean, :banner =>
"Use the rubygems modern index instead of the API endpoint"
method_option "jobs", :aliases => "-j", :type => :numeric, :banner =>
"Specify the number of jobs to run in parallel"
+ method_option "group", :aliases => "-g", :type => :array, :banner =>
+ "Update a specific group"
def update(*gems)
sources = Array(options[:source])
+ groups = Array(options[:group]).map(&:to_sym)
Bundler.ui.level = "warn" if options[:quiet]
- if gems.empty? && sources.empty?
+ if gems.empty? && sources.empty? && groups.empty?
# We're doing a full update
Bundler.definition(true)
else
# cycle through the requested gems, just to make sure they exist
names = Bundler.locked_gems.specs.map{ |s| s.name }
gems.each do |g|
next if names.include?(g)
raise GemNotFound, not_found_message(g, names)
end
+
+ if groups.any?
+ specs = Bundler.definition.specs_for groups
+ sources.concat(specs.map(&:name))
+ end
+
Bundler.definition(:gems => gems, :sources => sources)
end
Bundler::Fetcher.disable_endpoint = options["full-index"]
@@ -511,22 +519,27 @@
desc "package", "Locks and then caches all of the gems into vendor/cache"
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
method_option "all", :type => :boolean, :banner => "Include all sources (including path and git)."
method_option "quiet", :type => :boolean, :banner => "Only output warnings and errors."
+ method_option "path", :type => :string, :banner =>
+ "Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on this machine"
+ method_option "gemfile", :type => :string, :banner => "Use the specified gemfile instead of Gemfile"
long_desc <<-D
The package command will copy the .gem files for every gem in the bundle into the
directory ./vendor/cache. If you then check that directory into your source
control repository, others who check out your source will be able to install the
bundle without having to download any additional gems.
D
def package
Bundler.ui.level = "warn" if options[:quiet]
+ Bundler.settings[:path] = File.expand_path(options[:path]) if options[:path]
setup_cache_all
install
# TODO: move cache contents here now that all bundles are locked
- Bundler.load.cache
+ custom_path = Pathname.new(options[:path]) if options[:path]
+ Bundler.load.cache(custom_path)
end
map %w(pack) => :package
desc "exec", "Run the command in context of the bundle"
method_option :keep_file_descriptors, :type => :boolean, :default => false
@@ -648,24 +661,54 @@
def open(name)
editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
return Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR") unless editor
spec = select_spec(name, :regex_match)
return unless spec
- Dir.chdir(spec.full_gem_path) do
- command = "#{editor} #{spec.full_gem_path}"
+ full_gem_path = spec.full_gem_path
+ Dir.chdir(full_gem_path) do
+ command = "#{editor} #{full_gem_path}"
success = system(command)
Bundler.ui.info "Could not run '#{command}'" unless success
end
end
+ CONSOLES = {
+ 'pry' => :Pry,
+ 'ripl' => :Ripl,
+ 'irb' => :IRB,
+ }
+
desc "console [GROUP]", "Opens an IRB session with the bundle pre-loaded"
def console(group = nil)
group ? Bundler.require(:default, *(group.split.map! {|g| g.to_sym })) : Bundler.require
ARGV.clear
- require 'irb'
- IRB.start
+ preferred = Bundler.settings[:console] || 'irb'
+
+ # See if console is available
+ begin
+ require preferred || true
+ rescue LoadError
+ # Is it in Gemfile?
+ Bundler.ui.error "Could not load the #{preferred} console"
+ Bundler.ui.info "Falling back on IRB..."
+
+ require 'irb'
+ preferred = 'irb'
+ end
+
+ constant = CONSOLES[preferred]
+
+ console = begin
+ Object.const_get(constant)
+ rescue NameError => e
+ Bundler.ui.error e.inspect
+ Bundler.ui.error "Could not load the #{constant} console"
+ return
+ end
+
+ console.start
end
desc "version", "Prints the bundler's version information"
def version
Bundler.ui.info "Bundler version #{Bundler::VERSION}"
@@ -890,13 +933,11 @@
(num = input.to_i) > 0 ? specs[num - 1] : nil
end
end
def not_found_message(missing_gem_name, alternatives)
+ require 'bundler/similarity_detector'
message = "Could not find gem '#{missing_gem_name}'."
-
- # This is called as the result of a GemNotFound, let's see if
- # there's any similarly named ones we can propose instead
alternate_names = alternatives.map { |a| a.respond_to?(:name) ? a.name : a }
suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name)
message += "\nDid you mean #{suggestions}?" if suggestions
message
end