Class: PointmdComments::OptParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pointmd_comments/opt_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptParser

Returns a new instance of OptParser.



8
9
10
# File 'lib/pointmd_comments/opt_parser.rb', line 8

def initialize
  @options = {}
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/pointmd_comments/opt_parser.rb', line 6

def options
  @options
end

Instance Method Details

#parseObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



13
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
# File 'lib/pointmd_comments/opt_parser.rb', line 13

def parse
  OptionParser.new do |opts|
    opts.banner = 'Usage: pointmd_comments [options]'

    opts.on('-v', '--verbose', 'Show logs and backtraces') do |v|
      options[:verbose] = v
    end

    opts.on(
      '-sSOURCE',
      '--source=SOURCE',
      "A source to pull links from. Available sources are: #{Aggregators::Posts::ALLOWED_SOURCES}"
    ) do |s|
      options[:source] = s.to_sym
    end
    opts.on(
      '-o OUTPUT_PATH',
      '--output=OUTPUT_PATH',
      'A custom file path for the CSV.'
    ) do |p|
      options[:output] = p
    end
    opts.on('-V', '--version', 'Version') do
      puts PointmdComments::VERSION
      exit
    end
  end.parse!

  set_default_source unless options[:source] && options[:path]
  validate_source

  options
end