Parent

Included Modules

Class Index [+]

Quicksearch

Bundler::CLI

Public Class Methods

new(*) click to toggle source
    # File lib/bundler/cli.rb, line 13
13:     def initialize(*)
14:       super
15:       the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
16:       Bundler.ui = UI::Shell.new(the_shell)
17:       Bundler.ui.debug! if options["verbose"]
18:       Gem::DefaultUserInteraction.ui = UI::RGProxy.new(Bundler.ui)
19:     end
source_root() click to toggle source
     # File lib/bundler/cli.rb, line 499
499:     def self.source_root
500:       File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
501:     end

Public Instance Methods

cache() click to toggle source
     # File lib/bundler/cli.rb, line 308
308:     def cache
309:       Bundler.definition.resolve_with_cache!
310:       Bundler.load.cache
311:       Bundler.settings[:no_prune] = true if options[:no_prune]
312:       Bundler.load.lock
313:     rescue GemNotFound => e
314:       Bundler.ui.error(e.message)
315:       Bundler.ui.warn "Run `bundle install` to install missing gems."
316:       exit 128
317:     end
check() click to toggle source
     # File lib/bundler/cli.rb, line 99
 99:     def check
100:       ENV['BUNDLE_GEMFILE'] = File.expand_path(options[:gemfile]) if options[:gemfile]
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
config(name = nil, *args) click to toggle source
     # File lib/bundler/cli.rb, line 370
370:     def config(name = nil, *args)
371:       values = ARGV.dup
372:       values.shift # remove config
373:       values.shift # remove the name
374: 
375:       unless name
376:         Bundler.ui.confirm "Settings are listed in order of priority. The top value will be used.\n"
377: 
378:         Bundler.settings.all.each do |setting|
379:           Bundler.ui.confirm "#{setting}"
380:           with_padding do
381:             Bundler.settings.pretty_values_for(setting).each do |line|
382:               Bundler.ui.info line
383:             end
384:           end
385:           Bundler.ui.confirm ""
386:         end
387:         return
388:       end
389: 
390:       if values.empty?
391:         Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used"
392:         with_padding do
393:           Bundler.settings.pretty_values_for(name).each { |line| Bundler.ui.info line }
394:         end
395:       else
396:         locations = Bundler.settings.locations(name)
397: 
398:         if local = locations[:local]
399:           Bundler.ui.info "Your application has set #{name} to #{local.inspect}. This will override the "              "system value you are currently setting"
400:         end
401: 
402:         if global = locations[:global]
403:           Bundler.ui.info "You are replacing the current system value of #{name}, which is currently #{global}"
404:         end
405: 
406:         if env = locations[:env]
407:           Bundler.ui.info "You have set a bundler environment variable for #{env}. This will take precedence "              "over the system value you are setting"
408:         end
409: 
410:         Bundler.settings.set_global(name, values.join(" "))
411:       end
412:     end
console(group = nil) click to toggle source
     # File lib/bundler/cli.rb, line 432
432:     def console(group = nil)
433:       require 'bundler/setup'
434:       group ? Bundler.require(:default, group) : Bundler.require
435:       ARGV.clear
436: 
437:       require 'irb'
438:       IRB.start
439:     end
exec(*) click to toggle source
     # File lib/bundler/cli.rb, line 340
340:     def exec(*)
341:       ARGV.delete("exec")
342: 
343:       Bundler.setup
344: 
345:       begin
346:         # Run
347:         Kernel.exec(*ARGV)
348:       rescue Errno::EACCES
349:         Bundler.ui.error "bundler: not executable: #{ARGV.first}"
350:         exit 126
351:       rescue Errno::ENOENT
352:         Bundler.ui.error "bundler: command not found: #{ARGV.first}"
353:         Bundler.ui.warn  "Install missing gem binaries with `bundle install`"
354:         exit 127
355:       end
356:     end
gem(name) click to toggle source
     # File lib/bundler/cli.rb, line 479
479:     def gem(name)
480:       target = File.join(Dir.pwd, name)
481:       constant_name = name.split('_').map{|p| p.capitalize}.join
482:       constant_name = constant_name.split('-').map{|q| q.capitalize}.join('::') if constant_name =~ /-/
483:       constant_array = constant_name.split('::')
484:       FileUtils.mkdir_p(File.join(target, 'lib', name))
485:       opts = {:name => name, :constant_name => constant_name, :constant_array => constant_array}
486:       template(File.join("newgem/Gemfile.tt"),               File.join(target, "Gemfile"),                opts)
487:       template(File.join("newgem/Rakefile.tt"),              File.join(target, "Rakefile"),               opts)
488:       template(File.join("newgem/gitignore.tt"),             File.join(target, ".gitignore"),             opts)
489:       template(File.join("newgem/newgem.gemspec.tt"),        File.join(target, "#{name}.gemspec"),        opts)
490:       template(File.join("newgem/lib/newgem.rb.tt"),         File.join(target, "lib/#{name}.rb"),         opts)
491:       template(File.join("newgem/lib/newgem/version.rb.tt"), File.join(target, "lib/#{name}/version.rb"), opts)
492:       if options[:bin]
493:         template(File.join("newgem/bin/newgem.tt"),          File.join(target, 'bin', name),              opts)
494:       end
495:       Bundler.ui.info "Initializating git repo in #{target}"
496:       Dir.chdir(target) { `git init`; `git add .` }
497:     end
help(cli = nil) click to toggle source
    # File lib/bundler/cli.rb, line 27
27:     def help(cli = nil)
28:       case cli
29:       when "gemfile" then command = "gemfile.5"
30:       when nil       then command = "bundle"
31:       else command = "bundle-#{cli}"
32:       end
33: 
34:       manpages = %(
35:           bundle
36:           bundle-config
37:           bundle-exec
38:           bundle-install
39:           bundle-package
40:           bundle-update
41:           gemfile.5)
42: 
43:       if manpages.include?(command)
44:         root = File.expand_path("../man", __FILE__)
45: 
46:         if have_groff? && root !~ %{^file:/.+!/META-INF/jruby.home/.+}
47:           groff   = "groff -Wall -mtty-char -mandoc -Tascii"
48:           pager   = ENV['MANPAGER'] || ENV['PAGER'] || 'more'
49: 
50:           Kernel.exec "#{groff} #{root}/#{command} | #{pager}"
51:         else
52:           puts File.read("#{root}/#{command}.txt")
53:         end
54:       else
55:         super
56:       end
57:     end
init() click to toggle source
    # File lib/bundler/cli.rb, line 66
66:     def init
67:       opts = options.dup
68:       if File.exist?("Gemfile")
69:         Bundler.ui.error "Gemfile already exists at #{Dir.pwd}/Gemfile"
70:         exit 1
71:       end
72: 
73:       if opts[:gemspec]
74:         gemspec = File.expand_path(opts[:gemspec])
75:         unless File.exist?(gemspec)
76:           Bundler.ui.error "Gem specification #{gemspec} doesn't exist"
77:           exit 1
78:         end
79:         spec = Gem::Specification.load(gemspec)
80:         puts "Writing new Gemfile to #{Dir.pwd}/Gemfile"
81:         File.open('Gemfile', 'wb') do |file|
82:           file << "# Generated from #{gemspec}\n"
83:           file << spec.to_gemfile
84:         end
85:       else
86:         puts "Writing new Gemfile to #{Dir.pwd}/Gemfile"
87:         FileUtils.cp(File.expand_path('../templates/Gemfile', __FILE__), 'Gemfile')
88:       end
89:     end
install(path = nil) click to toggle source
     # File lib/bundler/cli.rb, line 157
157:     def install(path = nil)
158:       opts = options.dup
159:       opts[:without] ||= []
160:       if opts[:without].size == 1
161:         opts[:without].map!{|g| g.split(" ") }
162:         opts[:without].flatten!
163:       end
164:       opts[:without].map!{|g| g.to_sym }
165: 
166:       ENV['BUNDLE_GEMFILE'] = File.expand_path(opts[:gemfile]) if opts[:gemfile]
167:       ENV['RB_USER_INSTALL'] = '1' if Bundler::FREEBSD
168: 
169:       # Just disable color in deployment mode
170:       Bundler.ui.shell = Thor::Shell::Basic.new if opts[:deployment]
171: 
172:       if opts[:production]
173:         opts[:deployment] = true
174:         Bundler.ui.warn "The --production option is deprecated, and will be removed in "                          "the final release of Bundler 1.0. Please use --deployment instead."
175:       end
176: 
177:       if (path || opts[:path] || opts[:deployment]) && opts[:system]
178:         Bundler.ui.error "You have specified both a path to install your gems to, \n"                           "as well as --system. Please choose."
179:         exit 1
180:       end
181: 
182:       if path && opts[:path]
183:         Bundler.ui.error "You have specified a path via `bundle install #{path}` as well as\n"                           "by `bundle install --path #{options[:path]}`. These options are\n"                           "equivalent, so please use one or the other."
184:         exit 1
185:       end
186: 
187:       if opts["disable-shared-gems"]
188:         Bundler.ui.error "The disable-shared-gem option is no longer available.\n\n"                           "Instead, use `bundle install` to install to your system,\n"                           "or `bundle install --path path/to/gems` to install to an isolated\n"                           "location. Bundler will resolve relative paths relative to\n"                           "your `Gemfile`."
189:         exit 1
190:       end
191: 
192:       if opts[:deployment] || opts[:frozen]
193:         unless Bundler.default_lockfile.exist?
194:           flag = opts[:deployment] ? '--deployment' : '--frozen'
195:           raise ProductionError, "The #{flag} flag requires a Gemfile.lock. Please make "                                   "sure you have checked your Gemfile.lock into version control "                                   "before deploying."
196:         end
197: 
198:         if Bundler.root.join("vendor/cache").exist?
199:           opts[:local] = true
200:         end
201: 
202:         Bundler.settings[:frozen] = '1'
203:       end
204: 
205:       # Can't use Bundler.settings for this because settings needs gemfile.dirname
206:       Bundler.settings[:path] = nil if opts[:system]
207:       Bundler.settings[:path] = "vendor/bundle" if opts[:deployment]
208:       Bundler.settings[:path] = path if path
209:       Bundler.settings[:path] = opts[:path] if opts[:path]
210:       Bundler.settings[:bin] = opts["binstubs"] if opts[:binstubs]
211:       Bundler.settings[:disable_shared_gems] = '1' if Bundler.settings[:path]
212:       Bundler.settings.without = opts[:without] unless opts[:without].empty?
213:       Bundler.ui.be_quiet! if opts[:quiet]
214: 
215:       Installer.install(Bundler.root, Bundler.definition, opts)
216:       Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
217: 
218:       if Bundler.settings[:path]
219:         relative_path = Bundler.settings[:path]
220:         relative_path = "./" + relative_path unless relative_path[0] == //
221:         Bundler.ui.confirm "Your bundle is complete! " +
222:           "It was installed into #{relative_path}"
223:       else
224:         Bundler.ui.confirm "Your bundle is complete! " +
225:           "Use `bundle show [gemname]` to see where a bundled gem is installed."
226:       end
227: 
228:       if path
229:         Bundler.ui.warn "The path argument to `bundle install` is deprecated. " +
230:           "It will be removed in version 1.1. " +
231:           "Please use `bundle install --path #{path}` instead."
232:       end
233:     rescue GemNotFound => e
234:       if opts[:local]
235:         Bundler.ui.warn "Some gems seem to be missing from your vendor/cache directory."
236:       end
237: 
238:       if Bundler.definition.no_sources?
239:         Bundler.ui.warn "Your Gemfile doesn't have any sources. You can add one with a line like 'source :rubygems'"
240:       end
241:       raise e
242:     end
lock() click to toggle source
     # File lib/bundler/cli.rb, line 278
278:     def lock
279:       Bundler.ui.warn "Lock is deprecated. Your bundle is now locked whenever you run `bundle install`."
280:     end
open(name) click to toggle source
     # File lib/bundler/cli.rb, line 417
417:     def open(name)
418:       editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
419:       if editor
420:         gem_path = locate_gem(name)
421:         Dir.chdir(gem_path) do
422:           command = "#{editor} #{gem_path}"
423:           success = system(command)
424:           Bundler.ui.info "Could not run '#{command}'" unless success
425:         end
426:       else
427:         Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
428:       end
429:     end
package() click to toggle source
     # File lib/bundler/cli.rb, line 327
327:     def package
328:       install
329:       # TODO: move cache contents here now that all bundles are locked
330:       Bundler.load.cache
331:     end
show(gem_name = nil) click to toggle source
     # File lib/bundler/cli.rb, line 292
292:     def show(gem_name = nil)
293:       Bundler.load.lock
294: 
295:       if gem_name
296:         Bundler.ui.info locate_gem(gem_name)
297:       else
298:         Bundler.ui.info "Gems included by the bundle:"
299:         Bundler.load.specs.sort_by { |s| s.name }.each do |s|
300:           Bundler.ui.info "  * #{s.name} (#{s.version}#{s.git_version})"
301:         end
302:       end
303:     end
unlock() click to toggle source
     # File lib/bundler/cli.rb, line 283
283:     def unlock
284:       Bundler.ui.warn "Unlock is deprecated. To update to newer gem versions, use `bundle update`."
285:     end
update(*gems) click to toggle source
     # File lib/bundler/cli.rb, line 261
261:     def update(*gems)
262:       sources = Array(options[:source])
263: 
264:       if gems.empty? && sources.empty?
265:         # We're doing a full update
266:         Bundler.definition(true)
267:       else
268:         Bundler.definition(:gems => gems, :sources => sources)
269:       end
270: 
271:       Installer.install Bundler.root, Bundler.definition, "update" => true
272:       Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
273:       Bundler.ui.confirm "Your bundle is updated! " +
274:         "Use `bundle show [gemname]` to see where a bundled gem is installed."
275:     end
version() click to toggle source
     # File lib/bundler/cli.rb, line 442
442:     def version
443:       Bundler.ui.info "Bundler version #{Bundler::VERSION}"
444:     end
viz() click to toggle source
     # File lib/bundler/cli.rb, line 456
456:     def viz
457:       output_file = File.expand_path(options[:file])
458:       graph = Graph.new( Bundler.load )
459: 
460:       begin
461:         graph.viz(output_file, options[:version], options[:requirements])
462:         Bundler.ui.info output_file
463:       rescue LoadError => e
464:         Bundler.ui.error e.inspect
465:         Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
466:         Bundler.ui.warn "`gem install ruby-graphviz`"
467:       rescue StandardError => e
468:         if e.message =~ /GraphViz not installed or dot not in PATH/
469:           Bundler.ui.error e.message
470:           Bundler.ui.warn "The ruby graphviz gem requires GraphViz to be installed"
471:         else
472:           raise
473:         end
474:       end
475:     end

Private Instance Methods

have_groff?() click to toggle source
     # File lib/bundler/cli.rb, line 505
505:     def have_groff?
506:       !(`which groff` rescue '').empty?
507:     end
locate_gem(name) click to toggle source
     # File lib/bundler/cli.rb, line 509
509:     def locate_gem(name)
510:       spec = Bundler.load.specs.find{|s| s.name == name }
511:       raise GemNotFound, "Could not find gem '#{name}' in the current bundle." unless spec
512:       if spec.name == 'bundler'
513:         return File.expand_path('../../../', __FILE__)
514:       end
515:       spec.full_gem_path
516:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.