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

Returns a new instance of CLI.



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

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

Class Method Details

.executeObject



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

def self.execute
  opts = Slop.parse do |o|
    o.banner = "Bundler Patch Version #{Bundler::Patch::VERSION}\nUsage: bundle patch [options] [gems_to_update]"
    o.separator ''
    o.separator 'bundler-patch attempts to update gems conservatively.'
    o.separator ''
    o.bool '-m', '--minor_preferred', 'Prefer update to the latest minor.release version.' # TODO: change to --minor_preferred
    o.bool '-p', '--prefer_minimal', 'Prefer minimal version updates over most recent release (or minor if -m used).'
    o.bool '-s', '--strict_updates', 'Restrict any gem to be upgraded past most recent release (or minor if -m used).'
    o.bool '-l', '--list', 'List vulnerable gems and new version target. No updates will be performed.'
    o.bool '-v', '--vulnerable_gems_only', 'Only update vulnerable gems.'
    o.string '-a', '--advisory_db_path', 'Optional custom advisory db path. `gems` dir will be appended to this path.'
    o.on('-h', 'Show this help') { show_help(o) }
    o.on('--help', 'Show README.md') { show_readme }
  end

  show_readme if opts.arguments.include?('help')
  options = opts.to_hash
  options[:gems_to_update] = opts.arguments

  CLI.new.patch(options)
end

.show_help(opts) ⇒ Object



29
30
31
32
# File 'lib/bundler/patch/cli.rb', line 29

def self.show_help(opts)
  puts opts.to_s(prefix: '  ')
  exit
end

.show_readmeObject



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

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

Instance Method Details

#patch(options = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/bundler/patch/cli.rb', line 43

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

  return list(options) if options[:list]

  _patch(options)
end