Class: Punchlist::Options

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

Overview

Parse command line options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, source_finder_option_parser: SourceFinder::OptionParser.new) ⇒ Options

Returns a new instance of Options.



9
10
11
12
13
# File 'lib/punchlist/options.rb', line 9

def initialize(args,
               source_finder_option_parser: SourceFinder::OptionParser.new)
  @args = args
  @source_finder_option_parser = source_finder_option_parser
end

Instance Attribute Details

#default_punchlist_line_regexpObject (readonly)

Returns the value of attribute default_punchlist_line_regexp.



7
8
9
# File 'lib/punchlist/options.rb', line 7

def default_punchlist_line_regexp
  @default_punchlist_line_regexp
end

Instance Method Details

#parse_optionsObject



31
32
33
34
35
36
37
# File 'lib/punchlist/options.rb', line 31

def parse_options
  options = nil
  OptionParser.new do |opts|
    options = setup_options(opts)
  end.parse!(@args)
  options
end

#parse_regexp(opts, options) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/punchlist/options.rb', line 15

def parse_regexp(opts, options)
  opts.on('-r', '--regexp r',
          'Regexp to trigger on - ' \
          'default is XXX|TODO') do |v|
    options[:regexp] = v
  end
end

#setup_options(opts) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/punchlist/options.rb', line 23

def setup_options(opts)
  options = {}
  opts.banner = 'Usage: punchlist [options]'
  @source_finder_option_parser.add_options(opts, options)
  parse_regexp(opts, options)
  options
end