Class: LibyearBundler::Options
- Inherits:
-
Object
- Object
- LibyearBundler::Options
- Defined in:
- lib/libyear_bundler/options.rb
Overview
Uses OptionParser from Ruby’s stdlib to hand command-line arguments
Constant Summary collapse
- BANNER =
<<-BANNER.freeze Usage: libyear-bundler [Gemfile ...] [options] https://github.com/jaredbeck/libyear-bundler/ BANNER
Instance Method Summary collapse
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
- #parse ⇒ Object
Constructor Details
#initialize(argv) ⇒ Options
Returns a new instance of Options.
14 15 16 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 |
# File 'lib/libyear_bundler/options.rb', line 14 def initialize(argv) @argv = argv @options = ::OpenStruct.new @optparser = OptionParser.new do |opts| opts. = 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 |
Instance Method Details
#parse ⇒ Object
58 59 60 61 62 63 64 65 |
# 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 |