Class: PPStats::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/pp-stats/command-line.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CommandLine

Returns a new instance of CommandLine.



6
7
# File 'lib/pp-stats/command-line.rb', line 6

def initialize(args)
end

Instance Method Details

#runObject



9
10
11
12
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
46
# File 'lib/pp-stats/command-line.rb', line 9

def run
  options = {}
  optparse = OptionParser.new do |opts|
    opts.banner = "usage: pp-stats [options] modulepath"
    opts.on('--single-module', 'process a single module') do |flag|
      options[:single_module] = flag
    end
  end

  # Enforce required options and more graceful error handling.
  begin
    optparse.parse!
    # Not using required options anymore but I left it wired up.
    required = []
    missing = required.select { |param| options[param].nil? }
    if not missing.empty?
      PPStats::Format.errorf("missing options: #{missing.join(', ')}")
      exit
    end
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
    PPStats::Format.errorf($!.to_s) # $! is exception object
    exit
  end

  if ARGV.first.nil?
    options[:modulepath] = '.'
  else
    options[:modulepath] = ARGV.first
  end
  if !File.directory? options[:modulepath]
    PPStats::Format.errorf "module folder '#{options[:modulepath]}' not found"
    exit
  end

  processor = PPStats::Processor.new(options)
  processor.run
  processor.results
end