Class: R19Cov::OptionParser
- Inherits:
-
Object
- Object
- R19Cov::OptionParser
- Defined in:
- lib/r19cov/option_parser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(out = STDOUT, err = STDERR) ⇒ OptionParser
constructor
A new instance of OptionParser.
- #parse(args) ⇒ Object
Constructor Details
#initialize(out = STDOUT, err = STDERR) ⇒ OptionParser
Returns a new instance of OptionParser.
7 8 9 10 |
# File 'lib/r19cov/option_parser.rb', line 7 def initialize(out = STDOUT, err = STDERR) @out = out @err = err end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/r19cov/option_parser.rb', line 12 def @options end |
Instance Method Details
#parse(args) ⇒ Object
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 |
# File 'lib/r19cov/option_parser.rb', line 14 def parse(args) @options = Options.new if (idx = args.index('--')) extra_args = args[idx + 1 .. -1] args = args[0, idx].dup else extra_args = [] args = args.dup end @options. = args.dup args = ['--help'] if args.empty? ::OptionParser.new { |opt| opt. = "Usage: r19cov [options] (FILE|DIRECTORY)+ [-- --extra-options]" opt.on('-h', '--help', 'Show help messages') { @out.puts opt } opt.on('-o', '--output [OUTPUT_DIR]', 'Specifies output directory of coverage report') { |v| @options.output_dir = v } opt.on('-x', '--exclude [PATTERNS]', 'Don\'t generate info for files matching a pattern', '(comma-separated regexp list)') { |v| @options.exclude = v.split(/,/) } opt.on('-v', '--version', 'Show version') { @out.puts "r19cov #{R19Cov::VERSION}" } opt.parse!(args) } @options.targets = args @options. -= @options.targets ARGV.replace extra_args @options end |