Parent

Included Modules

Class Index [+]

Quicksearch

Bundler::CLI

Public Class Methods

new(*) click to toggle source
    # File lib/bundler/cli.rb, line 9
 9:     def initialize(*)
10:       super
11:       the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
12:       Bundler.ui = UI::Shell.new(the_shell)
13:       Bundler.ui.debug! if options["verbose"]
14:       Bundler.rubygems.ui = UI::RGProxy.new(Bundler.ui)
15:     end
source_root() click to toggle source
     # File lib/bundler/cli.rb, line 570
570:     def self.source_root
571:       File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
572:     end

Public Instance Methods

cache() click to toggle source
     # File lib/bundler/cli.rb, line 365
365:     def cache
366:       Bundler.definition.resolve_with_cache!
367:       Bundler.load.cache
368:       Bundler.settings[:no_prune] = true if options["no-prune"]
369:       Bundler.load.lock
370:     rescue GemNotFound => e
371:       Bundler.ui.error(e.message)
372:       Bundler.ui.warn "Run `bundle install` to install missing gems."
373:       exit 128
374:     end
check() click to toggle source
     # File lib/bundler/cli.rb, line 97
 97:     def check
 98:       ENV['BUNDLE_GEMFILE'] = File.expand_path(options[:gemfile]) if options[:gemfile]
 99: 
100:       Bundler.settings[:path] = File.expand_path(options[:path]) if options[:path]
101:       begin
102:         not_installed = Bundler.definition.missing_specs
103:       rescue GemNotFound, VersionConflict
104:         Bundler.ui.error "Your Gemfile's dependencies could not be satisfied"
105:         Bundler.ui.warn  "Install missing gems with `bundle install`"
106:         exit 1
107:       end
108: 
109:       if not_installed.any?
110:         Bundler.ui.error "The following gems are missing"
111:         not_installed.each { |s| Bundler.ui.error " * #{s.name} (#{s.version})" }
112:         Bundler.ui.warn "Install missing gems with `bundle install`"
113:         exit 1
114:       else
115:         Bundler.load.lock
116:         Bundler.ui.info "The Gemfile's dependencies are satisfied"
117:       end
118:     end
clean() click to toggle source
     # File lib/bundler/cli.rb, line 577
577:     def clean
578:       if Bundler.settings[:path] || options[:force]
579:         Bundler.load.clean
580:       else
581:         Bundler.ui.error "Can only use bundle clean when --path is set or --force is set"
582:         exit 1
583:       end
584:     end
config(name = nil, *args) click to toggle source
     # File lib/bundler/cli.rb, line 430
430:     def config(name = nil, *args)
431:       values = ARGV.dup
432:       values.shift # remove config
433:       values.shift # remove the name
434: 
435:       unless name
436:         Bundler.ui.confirm "Settings are listed in order of priority. The top value will be used.\n"
437: 
438:         Bundler.settings.all.each do |setting|
439:           Bundler.ui.confirm "#{setting}"
440:           with_padding do
441:             Bundler.settings.pretty_values_for(setting).each do |line|
442:               Bundler.ui.info line
443:             end
444:           end
445:           Bundler.ui.confirm ""
446:         end
447:         return
448:       end
449: 
450:       if values.empty?
451:         Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used"
452:         with_padding do
453:           Bundler.settings.pretty_values_for(name).each { |line| Bundler.ui.info line }
454:         end
455:       else
456:         locations = Bundler.settings.locations(name)
457: 
458:         if local = locations[:local]
459:           Bundler.ui.info "Your application has set #{name} to #{local.inspect}. This will override the "              "system value you are currently setting"
460:         end
461: 
462:         if global = locations[:global]
463:           Bundler.ui.info "You are replacing the current system value of #{name}, which is currently #{global}"
464:         end
465: 
466:         if env = locations[:env]
467:           Bundler.ui.info "You have set a bundler environment variable for #{env}. This will take precedence "              "over the system value you are setting"
468:         end
469: 
470:         Bundler.settings.set_global(name, values.join(" "))
471:       end
472:     end
console(group = nil) click to toggle source
     # File lib/bundler/cli.rb, line 492
492:     def console(group = nil)
493:       group ? Bundler.require(:default, *(group.split.map! {|g| g.to_sym })) : Bundler.require
494:       ARGV.clear
495: 
496:       require 'irb'
497:       IRB.start
498:     end
exec(*) click to toggle source
     # File lib/bundler/cli.rb, line 397
397:     def exec(*)
398:       ARGV.shift # remove "exec"
399: 
400:       Bundler.load.setup_environment
401: 
402:       begin
403:         # Run
404:         Kernel.exec(*ARGV)
405:       rescue Errno::EACCES
406:         Bundler.ui.error "bundler: not executable: #{ARGV.first}"
407:         exit 126
408:       rescue Errno::ENOENT
409:         Bundler.ui.error "bundler: command not found: #{ARGV.first}"
410:         Bundler.ui.warn  "Install missing gem executables with `bundle install`"
411:         exit 127
412:       rescue ArgumentError
413:         Bundler.ui.error "bundler: exec needs a command to run"
414:         exit 128
415:       end
416:     end
gem(name) click to toggle source
     # File lib/bundler/cli.rb, line 539
539:     def gem(name)
540:       name = name.chomp("/") # remove trailing slash if present
541:       target = File.join(Dir.pwd, name)
542:       constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..1] }.join
543:       constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..1] }.join('::') if constant_name =~ /-/
544:       constant_array = constant_name.split('::')
545:       FileUtils.mkdir_p(File.join(target, 'lib', name))
546:       git_user_name = `git config user.name`.chomp
547:       git_user_email = `git config user.email`.chomp
548:       opts = {
549:         :name           => name,
550:         :constant_name  => constant_name,
551:         :constant_array => constant_array,
552:         :author         => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
553:         :email          => git_user_email.empty? ? "TODO: Write your email address" : git_user_email
554:       }
555:       template(File.join("newgem/Gemfile.tt"),               File.join(target, "Gemfile"),                opts)
556:       template(File.join("newgem/Rakefile.tt"),              File.join(target, "Rakefile"),               opts)
557:       template(File.join("newgem/LICENSE.tt"),               File.join(target, "LICENSE"),                opts)
558:       template(File.join("newgem/README.md.tt"),             File.join(target, "README.md"),              opts)
559:       template(File.join("newgem/gitignore.tt"),             File.join(target, ".gitignore"),             opts)
560:       template(File.join("newgem/newgem.gemspec.tt"),        File.join(target, "#{name}.gemspec"),        opts)
561:       template(File.join("newgem/lib/newgem.rb.tt"),         File.join(target, "lib/#{name}.rb"),         opts)
562:       template(File.join("newgem/lib/newgem/version.rb.tt"), File.join(target, "lib/#{name}/version.rb"), opts)
563:       if options[:bin]
564:         template(File.join("newgem/bin/newgem.tt"),          File.join(target, 'bin', name),              opts)
565:       end
566:       Bundler.ui.info "Initializating git repo in #{target}"
567:       Dir.chdir(target) { `git init`; `git add .` }
568:     end
help(cli = nil) click to toggle source
    # File lib/bundler/cli.rb, line 23
23:     def help(cli = nil)
24:       case cli
25:       when "gemfile" then command = "gemfile.5"
26:       when nil       then command = "bundle"
27:       else command = "bundle-#{cli}"
28:       end
29: 
30:       manpages = %(
31:           bundle
32:           bundle-config
33:           bundle-exec
34:           bundle-install
35:           bundle-package
36:           bundle-update
37:           gemfile.5)
38: 
39:       if manpages.include?(command)
40:         root = File.expand_path("../man", __FILE__)
41: 
42:         if have_groff? && root !~ %{^file:/.+!/META-INF/jruby.home/.+}
43:           groff   = "groff -Wall -mtty-char -mandoc -Tascii"
44:           pager   = ENV['MANPAGER'] || ENV['PAGER'] || 'less -R'
45: 
46:           Kernel.exec "#{groff} #{root}/#{command} | #{pager}"
47:         else
48:           puts File.read("#{root}/#{command}.txt")
49:         end
50:       else
51:         super
52:       end
53:     end
init() click to toggle source
    # File lib/bundler/cli.rb, line 62
62:     def init
63:       opts = options.dup
64:       if File.exist?("Gemfile")
65:         Bundler.ui.error "Gemfile already exists at #{Dir.pwd}/Gemfile"
66:         exit 1
67:       end
68: 
69:       if opts[:gemspec]
70:         gemspec = File.expand_path(opts[:gemspec])
71:         unless File.exist?(gemspec)
72:           Bundler.ui.error "Gem specification #{gemspec} doesn't exist"
73:           exit 1
74:         end
75:         spec = Gem::Specification.load(gemspec)
76:         puts "Writing new Gemfile to #{Dir.pwd}/Gemfile"
77:         File.open('Gemfile', 'wb') do |file|
78:           file << "# Generated from #{gemspec}\n"
79:           file << spec.to_gemfile
80:         end
81:       else
82:         puts "Writing new Gemfile to #{Dir.pwd}/Gemfile"
83:         FileUtils.cp(File.expand_path('../templates/Gemfile', __FILE__), 'Gemfile')
84:       end
85:     end
install() click to toggle source
     # File lib/bundler/cli.rb, line 161
161:     def install
162:       opts = options.dup
163:       if opts[:without]
164:         opts[:without].map!{|g| g.split(" ") }
165:         opts[:without].flatten!
166:         opts[:without].map!{|g| g.to_sym }
167:       end
168: 
169:       # Can't use Bundler.settings for this because settings needs gemfile.dirname
170:       ENV['BUNDLE_GEMFILE'] = File.expand_path(opts[:gemfile]) if opts[:gemfile]
171:       ENV['RB_USER_INSTALL'] = '1' if Bundler::FREEBSD
172: 
173:       # Just disable color in deployment mode
174:       Bundler.ui.shell = Thor::Shell::Basic.new if opts[:deployment]
175: 
176:       if (opts[:path] || opts[:deployment]) && opts[:system]
177:         Bundler.ui.error "You have specified both a path to install your gems to, \n"                           "as well as --system. Please choose."
178:         exit 1
179:       end
180: 
181:       if opts[:deployment] || opts[:frozen]
182:         unless Bundler.default_lockfile.exist?
183:           flag = opts[:deployment] ? '--deployment' : '--frozen'
184:           raise ProductionError, "The #{flag} flag requires a Gemfile.lock. Please make "                                   "sure you have checked your Gemfile.lock into version control "                                   "before deploying."
185:         end
186: 
187:         if Bundler.root.join("vendor/cache").exist?
188:           opts[:local] = true
189:         end
190: 
191:         Bundler.settings[:frozen] = '1'
192:       end
193: 
194:       # When install is called with --no-deployment, disable deployment mode
195:       if opts[:deployment] == false
196:         Bundler.settings.delete(:frozen)
197:         opts[:system] = true
198:       end
199: 
200:       # Can't use Bundler.settings for this because settings needs gemfile.dirname
201:       Bundler.settings[:path]   = nil if opts[:system]
202:       Bundler.settings[:path]   = "vendor/bundle" if opts[:deployment]
203:       Bundler.settings[:path]   = opts[:path] if opts[:path]
204:       Bundler.settings[:path] ||= "bundle" if opts[:standalone]
205:       Bundler.settings[:bin]    = opts["binstubs"] if opts[:binstubs]
206:       Bundler.settings[:shebang] = opts["shebang"] if opts[:shebang]
207:       Bundler.settings[:no_prune] = true if opts["no-prune"]
208:       Bundler.settings[:disable_shared_gems] = Bundler.settings[:path] ? '1' : nil
209:       Bundler.settings.without = opts[:without]
210:       Bundler.ui.be_quiet! if opts[:quiet]
211:       Bundler.settings[:clean] = opts[:clean] if opts[:clean]
212: 
213:       Bundler::Fetcher.disable_endpoint = opts["full-index"]
214:       # rubygems plugins sometimes hook into the gem install process
215:       Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins)
216: 
217:       Installer.install(Bundler.root, Bundler.definition, opts)
218:       Bundler.load.cache if Bundler.root.join("vendor/cache").exist? && !options["no-cache"]
219: 
220:       if Bundler.settings[:path]
221:         absolute_path = File.expand_path(Bundler.settings[:path])
222:         relative_path = absolute_path.sub(File.expand_path('.'), '.')
223:         Bundler.ui.confirm "Your bundle is complete! " +
224:           "It was installed into #{relative_path}"
225:       else
226:         Bundler.ui.confirm "Your bundle is complete! " +
227:           "Use `bundle show [gemname]` to see where a bundled gem is installed."
228:       end
229:       Installer.post_install_messages.to_a.each do |name, msg|
230:         Bundler.ui.confirm "Post-install message from #{name}:\n#{msg}"
231:       end
232: 
233:       clean if Bundler.settings[:clean] && Bundler.settings[:path]
234:     rescue GemNotFound => e
235:       if opts[:local] && Bundler.app_cache.exist?
236:         Bundler.ui.warn "Some gems seem to be missing from your vendor/cache directory."
237:       end
238: 
239:       if Bundler.definition.no_sources?
240:         Bundler.ui.warn "Your Gemfile has no remote sources. If you need "            "gems that are not already on\nyour machine, add a line like this "            "to your Gemfile:\n    source 'https://rubygems.org'"
241:       end
242:       raise e
243:     end
open(name) click to toggle source
     # File lib/bundler/cli.rb, line 477
477:     def open(name)
478:       editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
479:       if editor
480:         gem_path = locate_gem(name)
481:         Dir.chdir(gem_path) do
482:           command = "#{editor} #{gem_path}"
483:           success = system(command)
484:           Bundler.ui.info "Could not run '#{command}'" unless success
485:         end
486:       else
487:         Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
488:       end
489:     end
outdated(*gems) click to toggle source
     # File lib/bundler/cli.rb, line 315
315:     def outdated(*gems)
316:       sources = Array(options[:source])
317:       current_specs = Bundler.load.specs
318: 
319:       if gems.empty? && sources.empty?
320:         # We're doing a full update
321:         definition = Bundler.definition(true)
322:       else
323:         definition = Bundler.definition(:gems => gems, :sources => sources)
324:       end
325:       options["local"] ? definition.resolve_with_cache! : definition.resolve_remotely!
326: 
327:       Bundler.ui.info ""
328:       if options["pre"]
329:         Bundler.ui.info "Outdated gems included in the bundle (including pre-releases):"
330:       else
331:         Bundler.ui.info "Outdated gems included in the bundle:"
332:       end
333: 
334:       out_count = 0
335:       # Loop through the current specs
336:       current_specs.each do |current_spec|
337:         next if !gems.empty? && !gems.include?(current_spec.name)
338: 
339:         active_spec = definition.index[current_spec.name].sort_by { |b| b.version }
340: 
341:         if !current_spec.version.prerelease? && !options[:pre] && active_spec.size > 1
342:           active_spec = active_spec.delete_if { |b| b.respond_to?(:version) && b.version.prerelease? }
343:         end
344: 
345:         active_spec = active_spec.last
346:         next if active_spec.nil?
347: 
348:         gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
349:         git_outdated = current_spec.git_version != active_spec.git_version
350:         if gem_outdated || git_outdated
351:           spec_version    = "#{active_spec.version}#{active_spec.git_version}"
352:           current_version = "#{current_spec.version}#{current_spec.git_version}"
353:           Bundler.ui.info "  * #{active_spec.name} (#{spec_version} > #{current_version})"
354:           out_count += 1
355:         end
356:         Bundler.ui.debug "from #{active_spec.loaded_from}"
357:       end
358: 
359:       Bundler.ui.info "  Your bundle is up to date!" if out_count < 1
360:       Bundler.ui.info ""
361:     end
package() click to toggle source
     # File lib/bundler/cli.rb, line 384
384:     def package
385:       install
386:       # TODO: move cache contents here now that all bundles are locked
387:       Bundler.load.cache
388:     end
show(gem_name = nil) click to toggle source
     # File lib/bundler/cli.rb, line 287
287:     def show(gem_name = nil)
288:       Bundler.load.lock
289: 
290:       if gem_name
291:         Bundler.ui.info locate_gem(gem_name)
292:       elsif options[:paths]
293:         Bundler.load.specs.sort_by { |s| s.name }.each do |s|
294:           Bundler.ui.info locate_gem(s.name)
295:         end
296:       else
297:         Bundler.ui.info "Gems included by the bundle:"
298:         Bundler.load.specs.sort_by { |s| s.name }.each do |s|
299:           Bundler.ui.info "  * #{s.name} (#{s.version}#{s.git_version})"
300:         end
301:       end
302:     end
update(*gems) click to toggle source
     # File lib/bundler/cli.rb, line 259
259:     def update(*gems)
260:       sources = Array(options[:source])
261: 
262:       if gems.empty? && sources.empty?
263:         # We're doing a full update
264:         Bundler.definition(true)
265:       else
266:         Bundler.definition(:gems => gems, :sources => sources)
267:       end
268: 
269:       opts = {"update" => true, "local" => options[:local]}
270:       # rubygems plugins sometimes hook into the gem install process
271:       Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins)
272: 
273:       Installer.install Bundler.root, Bundler.definition, opts
274:       Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
275:       clean if Bundler.settings[:clean] && Bundler.settings[:path]
276:       Bundler.ui.confirm "Your bundle is updated! " +
277:         "Use `bundle show [gemname]` to see where a bundled gem is installed."
278:     end
version() click to toggle source
     # File lib/bundler/cli.rb, line 501
501:     def version
502:       Bundler.ui.info "Bundler version #{Bundler::VERSION}"
503:     end
viz() click to toggle source
     # File lib/bundler/cli.rb, line 516
516:     def viz
517:       output_file = File.expand_path(options[:file])
518:       output_format = options[:format]
519:       graph = Graph.new(Bundler.load, output_file, options[:version], options[:requirements], options[:format])
520: 
521:       begin
522:         graph.viz
523:       rescue LoadError => e
524:         Bundler.ui.error e.inspect
525:         Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
526:         Bundler.ui.warn "`gem install ruby-graphviz`"
527:       rescue StandardError => e
528:         if e.message =~ /GraphViz not installed or dot not in PATH/
529:           Bundler.ui.error e.message
530:           Bundler.ui.warn "The ruby graphviz gem requires GraphViz to be installed"
531:         else
532:           raise
533:         end
534:       end
535:     end

Private Instance Methods

have_groff?() click to toggle source
     # File lib/bundler/cli.rb, line 588
588:     def have_groff?
589:       !(`which groff` rescue '').empty?
590:     end
locate_gem(name) click to toggle source
     # File lib/bundler/cli.rb, line 592
592:     def locate_gem(name)
593:       spec = Bundler.load.specs.find{|s| s.name == name }
594:       raise GemNotFound, "Could not find gem '#{name}' in the current bundle." unless spec
595:       if spec.name == 'bundler'
596:         return File.expand_path('../../../', __FILE__)
597:       end
598:       spec.full_gem_path
599:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.