Class: Punchlist::OptionParser
- Inherits:
-
Object
- Object
- Punchlist::OptionParser
- Defined in:
- lib/punchlist/option_parser.rb
Overview
Parse command line options
Instance Attribute Summary collapse
-
#default_punchlist_line_regexp ⇒ Object
readonly
Returns the value of attribute default_punchlist_line_regexp.
Instance Method Summary collapse
- #generate_config(source_file_globber) ⇒ Object
-
#initialize(args, source_finder_option_parser: SourceFinder::OptionParser.new) ⇒ OptionParser
constructor
A new instance of OptionParser.
- #parse_regexp(opts, options) ⇒ Object
- #setup_options(opts) ⇒ Object
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_regexp ⇒ Object (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) = nil ::OptionParser.new do |opts| = (opts) end.parse!(@args) Config.new(**, 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, ) opts.on('-r', '--regexp r', 'Regexp to trigger upon - default is ' \ "#{Config.default_punchlist_line_regexp_string}") do |v| [:regexp] = v end end |
#setup_options(opts) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/punchlist/option_parser.rb', line 26 def (opts) = {} opts. = 'Usage: punchlist [options]' @source_finder_option_parser.(opts, ) parse_regexp(opts, ) end |