Class: Bundler::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/bundler/cli.rb

Defined Under Namespace

Modules: Common Classes: Binstubs, Cache, Check, Clean, Config, Console, Exec, Gem, Init, Inject, Install, Lock, Open, Outdated, Package, Platform, Show, Update, Viz

Constant Summary collapse

AUTO_INSTALL_CMDS =
%w(show binstubs outdated exec open console licenses clean).freeze

Constants inherited from Thor

Thor::AmbiguousTaskError, Thor::DynamicTask, Thor::HELP_MAPPINGS, Thor::HiddenTask, Thor::TEMPLATE_EXTNAME, Thor::THOR_RESERVED_WORDS, Thor::Task, Thor::UndefinedTaskError, Thor::VERSION

Instance Attribute Summary

Attributes included from Thor::Actions

#behavior

Attributes included from Thor::Base

#args, #options, #parent_options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Thor::Actions

#action, #append_to_file, #apply, #chmod, #comment_lines, #copy_file, #create_file, #create_link, #destination_root, #destination_root=, #directory, #empty_directory, #find_in_source_paths, #get, #gsub_file, #in_root, included, #inject_into_class, #insert_into_file, #inside, #link_file, #prepend_to_file, #relative_to_original_destination_root, #remove_file, #run, #run_ruby_script, #source_paths, #template, #thor, #uncomment_lines

Methods inherited from Thor

check_unknown_options!, check_unknown_options?, command_help, default_command, desc, help, long_desc, map, method_option, method_options, package_name, printable_commands, register, stop_on_unknown_option!, stop_on_unknown_option?, subcommand, subcommand_classes, subcommands

Methods included from Thor::Base

included, register_klass_file, subclass_files, subclasses

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bundler/cli.rb', line 17

def initialize(*args)
  super

  custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile]
  ENV["BUNDLE_GEMFILE"] = File.expand_path(custom_gemfile) if custom_gemfile && !custom_gemfile.empty?

  Bundler.settings[:retry] = options[:retry] if options[:retry]

  current_cmd = args.last[:current_command].name
  auto_install if AUTO_INSTALL_CMDS.include?(current_cmd)
rescue UnknownArgumentError => e
  raise InvalidOption, e.message
ensure
  self.options ||= {}
  Bundler.ui = UI::Shell.new(options)
  Bundler.ui.level = "debug" if options["verbose"]

  if ENV["RUBYGEMS_GEMDEPS"] && !ENV["RUBYGEMS_GEMDEPS"].empty?
    Bundler.ui.warn(
      "The RUBYGEMS_GEMDEPS environment variable is set. This enables RubyGems' " \
      "experimental Gemfile mode, which may conflict with Bundler and cause unexpected errors. " \
      "To remove this warning, unset RUBYGEMS_GEMDEPS.", :wrap => true)
  end
end

Class Method Details

.handle_no_command_error(command, has_namespace = $thor_runner) ⇒ Object



84
85
86
87
88
# File 'lib/bundler/cli.rb', line 84

def self.handle_no_command_error(command, has_namespace = $thor_runner)
  return super unless command_path = Bundler.which("bundler-#{command}")

  Kernel.exec(command_path, *ARGV[1..-1])
end

.reformatted_help_args(args) ⇒ Object

Reformat the arguments passed to bundle that include a –help flag into the corresponding ‘bundle help #command` call



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/bundler/cli.rb', line 438

def self.reformatted_help_args(args)
  bundler_commands = all_commands.keys
  help_flags = %w(--help -h)
  exec_commands = %w(exec e)
  help_used = args.select {|a| help_flags.include? a }
  exec_used = args.select {|a| exec_commands.include? a }
  command = args.select {|a| bundler_commands.include? a }
  if exec_used.any? && help_used.any?
    regex = /
        ( # Matches `exec --help` or `exec --help foo`
          (#{exec_commands.join("|")})
          \s
          (#{help_flags.join("|")})
          (.+)*
        )|
        ( # Matches `--help exec` or `--help exec foo`
          (#{help_flags.join("|")})
          \s
          (#{exec_commands.join("|")})
          (.+)*
        )
      /x
    arg_str = args.join(" ")
    if arg_str =~ regex
      %w(help exec)
    else
      args
    end
  elsif command.empty?
    abort("Could not find command \"#{args.join(" ")}\".")
  else
    ["help", command.first]
  end
end

.source_rootObject



387
388
389
# File 'lib/bundler/cli.rb', line 387

def self.source_root
  File.expand_path(File.join(File.dirname(__FILE__), "templates"))
end

.startObject



10
11
12
13
14
15
# File 'lib/bundler/cli.rb', line 10

def self.start(*)
  super
rescue Exception => e
  Bundler.ui = UI::Shell.new
  raise e
end

Instance Method Details

#binstubs(*gems) ⇒ Object



232
233
234
235
# File 'lib/bundler/cli.rb', line 232

def binstubs(*gems)
  require "bundler/cli/binstubs"
  Binstubs.new(options, gems).run
end

#cacheObject



264
265
266
267
# File 'lib/bundler/cli.rb', line 264

def cache
  require "bundler/cli/cache"
  Cache.new(options).run
end

#checkObject



115
116
117
118
# File 'lib/bundler/cli.rb', line 115

def check
  require "bundler/cli/check"
  Check.new(options).run
end

#cleanObject



396
397
398
399
# File 'lib/bundler/cli.rb', line 396

def clean
  require "bundler/cli/clean"
  Clean.new(options.dup).run
end

#config(*args) ⇒ Object



319
320
321
322
# File 'lib/bundler/cli.rb', line 319

def config(*args)
  require "bundler/cli/config"
  Config.new(options, args, self).run
end

#console(group = nil) ⇒ Object



331
332
333
334
# File 'lib/bundler/cli.rb', line 331

def console(group = nil)
  require "bundler/cli/console"
  Console.new(options, group).run
end

#envObject



432
433
434
# File 'lib/bundler/cli.rb', line 432

def env
  Env.new.write($stdout)
end

#exec(*args) ⇒ Object



302
303
304
305
# File 'lib/bundler/cli.rb', line 302

def exec(*args)
  require "bundler/cli/exec"
  Exec.new(options, args).run
end

#gem(name) ⇒ Object



382
383
384
385
# File 'lib/bundler/cli.rb', line 382

def gem(name)
  require "bundler/cli/gem"
  Gem.new(options, name, self).run
end

#help(cli = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bundler/cli.rb', line 51

def help(cli = nil)
  case cli
  when "gemfile" then command = "gemfile.5"
  when nil       then command = "bundle"
  else command = "bundle-#{cli}"
  end

  manpages = %w(
    bundle
    bundle-config
    bundle-exec
    bundle-gem
    bundle-install
    bundle-package
    bundle-update
    bundle-platform
    gemfile.5)

  if manpages.include?(command)
    root = File.expand_path("../man", __FILE__)

    if Bundler.which("man") && root !~ %r{^file:/.+!/META-INF/jruby.home/.+}
      Kernel.exec "man #{root}/#{command}"
    else
      puts File.read("#{root}/#{command}.txt")
    end
  elsif command_path = Bundler.which("bundler-#{cli}")
    Kernel.exec(command_path, "--help")
  else
    super
  end
end

#initObject



97
98
99
100
# File 'lib/bundler/cli.rb', line 97

def init
  require "bundler/cli/init"
  Init.new(options.dup).run
end

#inject(name, version, *gems) ⇒ Object



410
411
412
413
# File 'lib/bundler/cli.rb', line 410

def inject(name, version, *gems)
  require "bundler/cli/inject"
  Inject.new(options, name, version, gems).run
end

#installObject



171
172
173
174
175
176
177
178
# File 'lib/bundler/cli.rb', line 171

def install
  require "bundler/cli/install"
  no_install = Bundler.settings[:no_install]
  Bundler.settings[:no_install] = false if no_install == true
  Install.new(options.dup).run
ensure
  Bundler.settings[:no_install] = no_install unless no_install.nil?
end

#licensesObject



343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/bundler/cli.rb', line 343

def licenses
  Bundler.load.specs.sort_by {|s| s.license.to_s }.reverse_each do |s|
    gem_name = s.name
    license  = s.license || s.licenses

    if license.empty?
      Bundler.ui.warn "#{gem_name}: Unknown"
    else
      Bundler.ui.info "#{gem_name}: #{license}"
    end
  end
end

#lockObject



426
427
428
429
# File 'lib/bundler/cli.rb', line 426

def lock
  require "bundler/cli/lock"
  Lock.new(options).run
end

#open(name) ⇒ Object



325
326
327
328
# File 'lib/bundler/cli.rb', line 325

def open(name)
  require "bundler/cli/open"
  Open.new(options, name).run
end

#outdated(*gems) ⇒ Object



255
256
257
258
# File 'lib/bundler/cli.rb', line 255

def outdated(*gems)
  require "bundler/cli/outdated"
  Outdated.new(options, gems).run
end

#packageObject



288
289
290
291
# File 'lib/bundler/cli.rb', line 288

def package
  require "bundler/cli/package"
  Package.new(options).run
end

#platformObject



404
405
406
407
# File 'lib/bundler/cli.rb', line 404

def platform
  require "bundler/cli/platform"
  Platform.new(options).run
end

#show(gem_name = nil) ⇒ Object



216
217
218
219
# File 'lib/bundler/cli.rb', line 216

def show(gem_name = nil)
  require "bundler/cli/show"
  Show.new(options, gem_name).run
end

#update(*gems) ⇒ Object



202
203
204
205
# File 'lib/bundler/cli.rb', line 202

def update(*gems)
  require "bundler/cli/update"
  Update.new(options, gems).run
end

#versionObject



337
338
339
# File 'lib/bundler/cli.rb', line 337

def version
  Bundler.ui.info "Bundler version #{Bundler::VERSION}"
end

#vizObject



367
368
369
370
# File 'lib/bundler/cli.rb', line 367

def viz
  require "bundler/cli/viz"
  Viz.new(options).run
end