Class: LibyearBundler::Options

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

Overview

Uses OptionParser from Ruby’s stdlib to hand command-line arguments

Defined Under Namespace

Classes: Store

Constant Summary collapse

<<-BANNER.freeze
Usage: libyear-bundler [Gemfile ...] [options]
https://github.com/jaredbeck/libyear-bundler/
BANNER

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/libyear_bundler/options.rb', line 17

def initialize(argv)
  @argv = argv
  @options = Store.new
  @optparser = OptionParser.new do |opts|
    opts.banner = BANNER
    opts.program_name = 'libyear-bundler'
    opts.version = ::LibyearBundler::VERSION
    @options.send(:'libyears?=', true)

    opts.on_head('-h', '--help', 'Prints this help') do
      puts opts
      exit
    end

    opts.on('--all', 'Calculate all metrics') do
      @options.send(:'libyears?=', true)
      @options.send(:'releases?=', true)
      @options.send(:'versions?=', true)
    end

    opts.on('--cache=CACHE_PATH', 'Use a cache across runs') do |cache_path|
      @options.cache_path = cache_path
    end

    opts.on('--libyears', '[default] Calculate libyears out-of-date') do
      @options.send(:'libyears?=', true)
    end

    opts.on('--releases', 'Calculate number of releases out-of-date') do
      @options.send(:'libyears?=', false)
      @options.send(:'releases?=', true)
    end

    opts.on('--versions', 'Calculate major, minor, and patch versions out-of-date') do
      @options.send(:'libyears?=', false)
      @options.send(:'versions?=', true)
    end

    opts.on('--grand-total', 'Return value for given metric(s)') do
      @options.send(:'grand_total?=', true)
    end

    opts.on('--sort', 'Sort by selected metric(s), in descending order') do
      @options.send(:'sort?=', true)
    end

    opts.on('--json', 'Output JSON') do
      @options.send(:'json?=', true)
    end
  end
end

Instance Method Details

#parseObject



69
70
71
72
73
74
75
76
# File 'lib/libyear_bundler/options.rb', line 69

def parse
  @optparser.parse!(@argv)
  @options
rescue OptionParser::InvalidOption => e
  warn e
  warn @optparser.help
  exit ::LibyearBundler::CLI::E_INVALID_CLI_ARG
end