Class: Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/check_super_calls/arguments_parser.rb

Overview

Parses command line arguments

Class Method Summary collapse

Class Method Details

.parse(argv) ⇒ Object



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
46
47
48
# File 'lib/check_super_calls/arguments_parser.rb', line 15

def self.parse(argv)
  # If no arguments supplied, print help
  argv << '-h' if argv.empty?

  result = default_options

  options_parser = OptionParser.new do |o|
    o.banner = 'Usage: check-super-calls.rb [input directory]'

    o.on('-h',
         '--help',
         'Prints this help') do
      puts options_parser
      exit 0
    end
  end

  begin
    options_parser.parse!(argv)
  rescue StandardError => exception
    puts exception
    puts options_parser
    exit 1
  end

  result.input_directory = argv.pop
  if result.input_directory.nil? || !Dir.exist?(result.input_directory)
    puts 'Can\'t find directory ' + result.input_directory
    Parser.parse %w[--help]
    exit 0
  end

  result
end