Class: Bundler::Patch::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/patch/cli.rb,
lib/bundler/patch/cli_options.rb

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



59
60
61
# File 'lib/bundler/patch/cli.rb', line 59

def initialize
  @no_vulns_message = 'No known vulnerabilities to update.'
end

Class Method Details

.executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bundler/patch/cli.rb', line 9

def self.execute
  original_command = ARGV.join(' ')

  opts = Slop.parse! do
    banner "Bundler Patch Version #{Bundler::Patch::VERSION}\nUsage: bundle patch [options] [gems-to-update]\n\nbundler-patch attempts to update gems conservatively.\n"
    on '-m', '--minor', 'Prefer update to the latest minor.patch version.'
    on '-n', '--minimal', 'Prefer minimal version updates over most recent patch (or minor if -m used).'
    on '-s', '--strict', 'Restrict any gem to be upgraded past most recent patch (or minor if -m used).'
    on '-l', '--list', 'List vulnerable gems and new version target. No updates will be performed.'
    on '-v', '--vulnerable-gems-only', 'Only update vulnerable gems.'
    on '-a=', '--advisory-db-path=', 'Optional custom advisory db path. `gems` dir will be appended to this path.'
    on '-d=', '--ruby-advisory-db-path=', 'Optional path for ruby advisory db. `gems` dir will be appended to this path.'
    on '-r', '--ruby', 'Update Ruby version in related files.'
    on '--rubies=', 'Supported Ruby versions. Comma delimited or multiple switches.', as: Array, delimiter: ','
    on '-g=', '--gemfile=', 'Optional Gemfile to execute against. Defaults to Gemfile in current directory.'
    on '--use_target_ruby', 'Optionally attempt to use Ruby version of target bundle specified in --gemfile.'
    on '-h', 'Show this help'
    on '--help', 'Show README.md'

    # will be stripped in help display and normalized to hyphenated options
    on '--vulnerable_gems_only'
    on '--advisory_db_path='
    on '--ruby_advisory_db_path='
    on '-p', '--prefer_minimal'
    on '--minor_preferred'
    on '--strict_updates'
  end

  options = opts.to_hash
  options[:gems_to_update] = ARGV
  options[:original_command] = original_command
  STDERR.puts options.inspect if ENV['DEBUG']

  show_help(opts) if options[:h]
  show_readme if ARGV.include?('help') || options[:help]

  CLI.new.patch(options)
end

.show_help(slop) ⇒ Object



48
49
50
51
52
# File 'lib/bundler/patch/cli.rb', line 48

def self.show_help(slop)
  slop.options.delete_if { |o| o.long =~ /_/ }
  puts slop
  exit
end

.show_readmeObject



54
55
56
57
# File 'lib/bundler/patch/cli.rb', line 54

def self.show_readme
  Kernel.exec "less '#{File.expand_path('../../../../README.md', __FILE__)}'"
  exit
end

Instance Method Details

#launch_target_bundler_patch(options) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/bundler/patch/cli.rb', line 80

def launch_target_bundler_patch(options)
  tb = options[:target]
  ruby = tb.ruby_bin_exe
  tb.install_bundler_patch_in_target
  bundler_patch = File.join(tb.ruby_bin, 'bundler-patch')
  full_command = %Q{GEM_HOME="#{tb.gem_home}" "#{ruby}" "#{bundler_patch}" #{options[:original_command].gsub(/use_target_ruby/, '')}}
  result = shell_command(full_command)
  puts result[:stdout] unless ENV['BP_DEBUG']
end

#patch(options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bundler/patch/cli.rb', line 63

def patch(options={})
  Bundler.ui = Bundler::UI::Shell.new

  options = Bundler::Patch::CLI::Options.new.normalize_options(options)

  tb = options[:target]
  if options[:use_target_ruby] && tb.target_ruby_is_different?
    launch_target_bundler_patch(options)
  else
    return list(options) if options[:list]

    patch_ruby(options) if options[:ruby]

    patch_gems(options)
  end
end