Class: Bunup::Options

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/bunup/options.rb

Overview

Handle command-line switches

Class Method Summary collapse

Class Method Details

.parse!(args) ⇒ Object



7
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
33
34
35
36
# File 'lib/bunup/options.rb', line 7

def self.parse!(args)
  args = ['--all'] if args.empty?
  options = new
  opt_parser = ::OptionParser.new do |opts|
    opts.banner = 'Usage: bunup [options] | <gem_name> [<gem_name>...]'
    opts.program_name = 'bunup'
    opts.version = ::Bunup::VERSION

    opts.on('--all', 'Update all outdated gems (default)') do
      options.all = true
    end

    assume_yes_msg = 'Answer "yes" to major version update prompts ' \
      'and run non-interactively'
    opts.on('-y', '--yes', '--assume-yes', assume_yes_msg) do
      options.assume_yes = true
    end

    opts.on('-h', '--help', 'Prints this help') do
      puts opts
      exit
    end
  end
  opt_parser.parse!(args)
  options
rescue OptionParser::InvalidOption => e
  puts e
  puts opt_parser
  abort
end