Class: TcpsnitchAnalyzer::OptParser

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

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



6
7
8
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tcpsnitch_analyzer/opt_parser.rb', line 6

def self.parse(args)
  options = OpenStruct.new
  options.analysis_type = ProportionStat
  options.event_filter = nil 
  options.node_path = "type"
    
  begin
    OptionParser.new do |opts|
      opts.banner = "Usage: #{EXECUTABLE} [-h] [options] file...\n"
      opts.separator ""
      opts.separator "Analyze tcpsnitch JSON traces."
      opts.separator ""
      opts.separator "Options:"
      
      opts.on("-a", "--analysis [TYPE]", "TYPE of statistic analysis: 
              descriptive (d), proportion (p) or timeserie (t).") do |type|
        TcpsnitchAnalyzer.error("missing -a argument") unless type 

        case type.downcase
        when /^d.*/
          options.analysis_type = DescriptiveStat
        when /^p.*/
          options.analysis_type = ProportionStat
        when /^t.*/
          options.analysis_type = TimeSerieStat
        else
          TcpsnitchAnalyzer.error("invalid -a argument: '#{type}'")
        end
      end
   
      opts.on("-e", "--event [FILTER]", "filter on events of type FILTER") do |ev|
        TcpsnitchAnalyzer.error("missing -e argument") unless ev 
        options.event_filter = ev          
      end

      opts.on_tail("-h", "--help", "show this help text") do 
        puts opts
        exit
      end
   
      opts.on("-n", "--node [PATH]", "compute on node at PATH") do |node| 
        TcpsnitchAnalyzer.error("missing -n argument") unless node 
        options.node_path = node 
      end
   
      opts.on_tail("--version", "show version") do 
        puts VERSION
        exit
      end

    end.parse!(args) # OptionParser
  rescue OptionParser::ParseError => e 
    TcpsnitchAnalyzer.error(e)
  end

  options
end