class LibyearBundler::Options

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

Constants

Public Class Methods

new(argv) click to toggle source
# File lib/libyear_bundler/options.rb, line 14
def initialize(argv)
  @argv = argv
  @options = ::OpenStruct.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
  end
end

Public Instance Methods

parse() click to toggle source
# File lib/libyear_bundler/options.rb, line 58
def parse
  @optparser.parse!(@argv)
  @options
rescue OptionParser::InvalidOption => e
  warn e
  warn @optparser.help
  exit ::LibyearBundler::CLI::E_INVALID_CLI_ARG
end