Parent

Included Modules

Bundler::CLI

Public Class Methods

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

Public Instance Methods

cache() click to toggle source
     # File lib/bundler/cli.rb, line 289
289:     def cache
290:       Bundler.definition.resolve_with_cache!
291:       Bundler.load.cache
292:       Bundler.settings[:no_prune] = true if options[:no_prune]
293:       Bundler.load.lock
294:     rescue GemNotFound => e
295:       Bundler.ui.error(e.message)
296:       Bundler.ui.warn "Run `bundle install` to install missing gems."
297:       exit 128
298:     end
check() click to toggle source
     # File lib/bundler/cli.rb, line 98
 98:     def check
 99:       ENV['BUNDLE_GEMFILE'] = File.expand_path(options[:gemfile]) if options[:gemfile]
100:       begin
101:         not_installed = Bundler.definition.missing_specs
102:       rescue GemNotFound, VersionConflict
103:         Bundler.ui.error "Your Gemfile's dependencies could not be satisfied"
104:         Bundler.ui.warn  "Install missing gems with `bundle install`"
105:         exit 1
106:       end
107: 
108:       if not_installed.any?
109:         Bundler.ui.error "The following gems are missing"
110:         not_installed.each { |s| Bundler.ui.error " * #{s.name} (#{s.version})" }
111:         Bundler.ui.warn "Install missing gems with `bundle install`"
112:         exit 1
113:       else
114:         Bundler.load.lock
115:         Bundler.ui.info "The Gemfile's dependencies are satisfied"
116:       end
117:     end
config(name = nil, *args) click to toggle source
     # File lib/bundler/cli.rb, line 351
351:     def config(name = nil, *args)
352:       values = ARGV.dup
353:       values.shift # remove config
354:       values.shift # remove the name
355: 
356:       unless name
357:         Bundler.ui.confirm "Settings are listed in order of priority. The top value will be used.\n"
358: 
359:         Bundler.settings.all.each do |setting|
360:           Bundler.ui.confirm "#{setting}"
361:           with_padding do
362:             Bundler.settings.pretty_values_for(setting).each do |line|
363:               Bundler.ui.info line
364:             end
365:           end
366:           Bundler.ui.confirm ""
367:         end
368:         return
369:       end
370: 
371:       if values.empty?
372:         Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used"
373:         with_padding do
374:           Bundler.settings.pretty_values_for(name).each { |line| Bundler.ui.info line }
375:         end
376:       else
377:         locations = Bundler.settings.locations(name)
378: 
379:         if local = locations[:local]
380:           Bundler.ui.info "Your application has set #{name} to #{local.inspect}. This will override the "              "system value you are currently setting"
381:         end
382: 
383:         if global = locations[:global]
384:           Bundler.ui.info "You are replacing the current system value of #{name}, which is currently #{global}"
385:         end
386: 
387:         if env = locations[:env]
388:           Bundler.ui.info "You have set a bundler environment variable for #{env}. This will take precedence "              "over the system value you are setting"
389:         end
390: 
391:         Bundler.settings.set_global(name, values.join(" "))
392:       end
393:     end
console(group = nil) click to toggle source
     # File lib/bundler/cli.rb, line 410
410:     def console(group = nil)
411:       require 'bundler/setup'
412:       group ? Bundler.require(:default, group) : Bundler.require
413:       ARGV.clear
414: 
415:       require 'irb'
416:       IRB.start
417:     end
exec(*) click to toggle source
     # File lib/bundler/cli.rb, line 321
321:     def exec(*)
322:       ARGV.delete("exec")
323: 
324:       Bundler.setup
325: 
326:       begin
327:         # Run
328:         Kernel.exec(*ARGV)
329:       rescue Errno::EACCES
330:         Bundler.ui.error "bundler: not executable: #{ARGV.first}"
331:         exit 126
332:       rescue Errno::ENOENT
333:         Bundler.ui.error "bundler: command not found: #{ARGV.first}"
334:         Bundler.ui.warn  "Install missing gem binaries with `bundle install`"
335:         exit 127
336:       end
337:     end
gem(name) click to toggle source
     # File lib/bundler/cli.rb, line 456
456:     def gem(name)
457:       target = File.join(Dir.pwd, name)
458:       if File.exist?(name)
459:         Bundler.ui.error "File already exists at #{File.join(Dir.pwd, name)}"
460:         exit 1
461:       end
462: 
463:       constant_name = name.split('_').map{|p| p.capitalize}.join
464:       constant_name = constant_name.split('-').map{|q| q.capitalize}.join('::') if constant_name =~ /-/
465:       constant_array = constant_name.split('::')
466:       FileUtils.mkdir_p(File.join(target, 'lib', name))
467:       opts = {:name => name, :constant_name => constant_name, :constant_array => constant_array}
468:       template(File.join('newgem', 'Gemfile.tt'),                     File.join(target, 'Gemfile'),                 opts)
469:       template(File.join('newgem', 'Rakefile.tt'),                    File.join(target, 'Rakefile'),                opts)
470:       template(File.join('newgem', 'gitignore.tt'),                   File.join(target, '.gitignore'),              opts)
471:       template(File.join('newgem', 'newgem.gemspec.tt'),              File.join(target, "#{name}.gemspec"),         opts)
472:       template(File.join('newgem', 'lib', 'newgem.rb.tt'),            File.join(target, 'lib', "#{name}.rb"),       opts)
473:       template(File.join('newgem', 'lib', 'newgem', 'version.rb.tt'), File.join(target, 'lib', name, 'version.rb'), opts)
474:       Bundler.ui.info "Initializating git repo in #{target}"
475:       Dir.chdir(target) { `git init`; `git add .` }
476:     end
help(cli = nil) click to toggle source
    # File lib/bundler/cli.rb, line 26
26:     def help(cli = nil)
27:       case cli
28:       when "gemfile" then command = "gemfile.5"
29:       when nil       then command = "bundle"
30:       else command = "bundle-#{cli}"
31:       end
32: 
33:       manpages = %(
34:           bundle
35:           bundle-config
36:           bundle-exec
37:           bundle-install
38:           bundle-package
39:           bundle-update
40:           gemfile.5)
41: 
42:       if manpages.include?(command)
43:         root = File.expand_path("../man", __FILE__)
44: 
45:         if have_groff?
46:           groff   = "groff -Wall -mtty-char -mandoc -Tascii"
47:           pager   = ENV['MANPAGER'] || ENV['PAGER'] || 'more'
48: 
49:           Kernel.exec "#{groff} #{root}/#{command} | #{pager}"
50:         else
51:           puts File.read("#{root}/#{command}.txt")
52:         end
53:       else
54:         super
55:       end
56:     end
init() click to toggle source
    # File lib/bundler/cli.rb, line 65
65:     def init
66:       opts = options.dup
67:       if File.exist?("Gemfile")
68:         Bundler.ui.error "Gemfile already exists at #{Dir.pwd}/Gemfile"
69:         exit 1
70:       end
71: 
72:       if opts[:gemspec]
73:         gemspec = File.expand_path(opts[:gemspec])
74:         unless File.exist?(gemspec)
75:           Bundler.ui.error "Gem specification #{gemspec} doesn't exist"
76:           exit 1
77:         end
78:         spec = Gem::Specification.load(gemspec)
79:         puts "Writing new Gemfile to #{Dir.pwd}/Gemfile"
80:         File.open('Gemfile', 'wb') do |file|
81:           file << "# Generated from #{gemspec}\n"
82:           file << spec.to_gemfile
83:         end
84:       else
85:         puts "Writing new Gemfile to #{Dir.pwd}/Gemfile"
86:         FileUtils.cp(File.expand_path('../templates/Gemfile', __FILE__), 'Gemfile')
87:       end
88:     end
install(path = nil) click to toggle source
     # File lib/bundler/cli.rb, line 156
156:     def install(path = nil)
157:       opts = options.dup
158:       opts[:without] ||= []
159:       opts[:without].map! { |g| g.to_sym }
160: 
161: 
162:       ENV['BUNDLE_GEMFILE'] = File.expand_path(opts[:gemfile]) if opts[:gemfile]
163: 
164:       if opts[:production]
165:         opts[:deployment] = true
166:         Bundler.ui.warn "The --production option is deprecated, and will be removed in "                          "the final release of Bundler 1.0. Please use --deployment instead."
167:       end
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:         Bundler.settings[:frozen] = '1'
186: 
187:         unless Bundler.default_lockfile.exist?
188:           flag = opts[:deployment] ? '--deployment' : '--frozen'
189:           raise ProductionError, "The #{flag} flag requires a Gemfile.lock. Please make "                                   "sure you have checked your Gemfile.lock into version control "                                   "before deploying."
190:         end
191: 
192:         if Bundler.root.join("vendor/cache").exist?
193:           opts[:local] = true
194:         end
195:       end
196: 
197:       # Can't use Bundler.settings for this because settings needs gemfile.dirname
198:       Bundler.settings[:path] = nil if opts[:system]
199:       Bundler.settings[:path] = "vendor/bundle" if opts[:deployment]
200:       Bundler.settings[:path] = path if path
201:       Bundler.settings[:path] = opts[:path] if opts[:path]
202:       Bundler.settings[:bin] = opts["binstubs"] if opts[:binstubs]
203:       Bundler.settings[:disable_shared_gems] = '1' if Bundler.settings[:path]
204:       Bundler.settings.without = opts[:without]
205:       Bundler.ui.be_quiet! if opts[:quiet]
206: 
207:       Installer.install(Bundler.root, Bundler.definition, opts)
208:       Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
209:       Bundler.ui.confirm "Your bundle is complete! " +
210:         "Use `bundle show [gemname]` to see where a bundled gem is installed."
211: 
212:       Bundler.ui.confirm "\nYour bundle was installed to `#{Bundler.settings[:path]}`" if Bundler.settings[:path]
213: 
214:       if path
215:         Bundler.ui.warn "\nIf you meant to install it to your system, please remove the\n"                          "`#{path}` directory and run `bundle install --system`"
216:       end
217:     rescue GemNotFound => e
218:       if Bundler.definition.no_sources?
219:         Bundler.ui.warn "Your Gemfile doesn't have any sources. You can add one with a line like 'source :gemcutter'"
220:       end
221:       raise e
222:     end
lock() click to toggle source
     # File lib/bundler/cli.rb, line 259
259:     def lock
260:       Bundler.ui.warn "Lock is deprecated. Your bundle is now locked whenever you run `bundle install`."
261:     end
open(name) click to toggle source
     # File lib/bundler/cli.rb, line 398
398:     def open(name)
399:       editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
400:       if editor
401:         command = "#{editor} #{locate_gem(name)}"
402:         success = system(command)
403:         Bundler.ui.info "Could not run '#{command}'" unless success
404:       else
405:         Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
406:       end
407:     end
package() click to toggle source
     # File lib/bundler/cli.rb, line 308
308:     def package
309:       install
310:       # TODO: move cache contents here now that all bundles are locked
311:       Bundler.load.cache
312:     end
show(gem_name = nil) click to toggle source
     # File lib/bundler/cli.rb, line 273
273:     def show(gem_name = nil)
274:       Bundler.load.lock
275: 
276:       if gem_name
277:         Bundler.ui.info locate_gem(gem_name)
278:       else
279:         Bundler.ui.info "Gems included by the bundle:"
280:         Bundler.load.specs.sort_by { |s| s.name }.each do |s|
281:           Bundler.ui.info "  * #{s.name} (#{s.version}#{s.git_version})"
282:         end
283:       end
284:     end
unlock() click to toggle source
     # File lib/bundler/cli.rb, line 264
264:     def unlock
265:       Bundler.ui.warn "Unlock is deprecated. To update to newer gem versions, use `bundle update`."
266:     end
update(*gems) click to toggle source
     # File lib/bundler/cli.rb, line 242
242:     def update(*gems)
243:       sources = Array(options[:source])
244: 
245:       if gems.empty? && sources.empty?
246:         # We're doing a full update
247:         Bundler.definition(true)
248:       else
249:         Bundler.definition(:gems => gems, :sources => sources)
250:       end
251: 
252:       Installer.install Bundler.root, Bundler.definition, "update" => true
253:       Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
254:       Bundler.ui.confirm "Your bundle is updated! " +
255:         "Use `bundle show [gemname]` to see where a bundled gem is installed."
256:     end
version() click to toggle source
     # File lib/bundler/cli.rb, line 420
420:     def version
421:       Bundler.ui.info "Bundler version #{Bundler::VERSION}"
422:     end
viz() click to toggle source
     # File lib/bundler/cli.rb, line 434
434:     def viz
435:       output_file = File.expand_path(options[:file])
436:       graph = Graph.new( Bundler.load )
437: 
438:       begin
439:         graph.viz(output_file, options[:version], options[:requirements])
440:         Bundler.ui.info output_file
441:       rescue LoadError => e
442:         Bundler.ui.error e.inspect
443:         Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
444:         Bundler.ui.warn "`gem install ruby-graphviz`"
445:       rescue StandardError => e
446:         if e.message =~ /GraphViz not installed or dot not in PATH/
447:           Bundler.ui.error e.message
448:           Bundler.ui.warn "The ruby graphviz gem requires GraphViz to be installed"
449:         else
450:           raise
451:         end
452:       end
453:     end

Private Instance Methods

have_groff?() click to toggle source
     # File lib/bundler/cli.rb, line 484
484:     def have_groff?
485:       `which groff 2>#{NULL}`
486:       $? == 0
487:     end
locate_gem(name) click to toggle source
     # File lib/bundler/cli.rb, line 489
489:     def locate_gem(name)
490:       spec = Bundler.load.specs.find{|s| s.name == name }
491:       raise GemNotFound, "Could not find gem '#{name}' in the current bundle." unless spec
492:       if spec.name == 'bundler'
493:         return File.expand_path('../../../', __FILE__)
494:       end
495:       spec.full_gem_path
496:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.