Class: Bundler::Patch::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI



44
45
46
# File 'lib/bundler/patch/cli.rb', line 44

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

Class Method Details

.executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bundler/patch/cli.rb', line 8

def self.execute
  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_preferred', 'Prefer update to the latest minor.release version.'
    on '-p', '--prefer_minimal', 'Prefer minimal version updates over most recent release (or minor if -m used).'
    on '-s', '--strict_updates', 'Restrict any gem to be upgraded past most recent release (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 '-h', 'Show this help'
    on '--help', 'Show README.md'
  end

  options = opts.to_hash
  options[:gems_to_update] = ARGV
  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(opts) ⇒ Object



34
35
36
37
# File 'lib/bundler/patch/cli.rb', line 34

def self.show_help(opts)
  puts opts
  exit
end

.show_readmeObject



39
40
41
42
# File 'lib/bundler/patch/cli.rb', line 39

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

Instance Method Details

#patch(options = {}) ⇒ Object



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

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

  return list(options) if options[:list]

  patch_ruby(options[:rubies]) if options[:ruby]

  patch_gems(options)
end