Class: Punchlist::OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/punchlist/option_parser.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) ⇒ OptionParser

Returns a new instance of OptionParser.



12
13
14
15
16
# File 'lib/punchlist/option_parser.rb', line 12

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.



10
11
12
# File 'lib/punchlist/option_parser.rb', line 10

def default_punchlist_line_regexp
  @default_punchlist_line_regexp
end

Instance Method Details

#generate_config(source_file_globber) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/punchlist/option_parser.rb', line 34

def generate_config(source_file_globber)
  options = nil
  ::OptionParser.new do |opts|
    options = setup_options(opts)
  end.parse!(@args)
  Config.new(**options, source_file_globber: source_file_globber)
end

#parse_regexp(opts, options) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/punchlist/option_parser.rb', line 18

def parse_regexp(opts, options)
  opts.on('-r', '--regexp r',
          'Regexp to trigger upon - default is ' \
          "#{Config.default_punchlist_line_regexp_string}") do |v|
    options[:regexp] = v
  end
end

#setup_options(opts) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/punchlist/option_parser.rb', line 26

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