Parent

Included Modules

Class Index [+]

Quicksearch

Bundler::CLI

Public Class Methods

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

Public Instance Methods

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

Private Instance Methods

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.