Class: Saikuro::CLI

Inherits:
Object
  • Object
show all
Includes:
ResultIndexGenerator
Defined in:
lib/saikuro/cli.rb

Instance Method Summary collapse

Methods included from ResultIndexGenerator

#list_analyzed_files, #print_summary_table_rows, #summarize_errors_and_warnings, #write_cyclo_index, #write_index, #write_token_index

Instance Method Details

#runObject



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/saikuro/cli.rb', line 12

def run

files = Array.new
output_dir = "./"
formater = "html"
state_filter = Filter.new(5)
token_filter = Filter.new(10, 25, 50)
comp_state = comp_token = false
begin
  opt = GetoptLong.new(
     ["-o","--output_directory", GetoptLong::REQUIRED_ARGUMENT],
     ["-h","--help", GetoptLong::NO_ARGUMENT],
     ["-f","--formater", GetoptLong::REQUIRED_ARGUMENT],
     ["-c","--cyclo", GetoptLong::NO_ARGUMENT],
     ["-t","--token", GetoptLong::NO_ARGUMENT],
     ["-y","--filter_cyclo", GetoptLong::REQUIRED_ARGUMENT],
     ["-k","--filter_token", GetoptLong::REQUIRED_ARGUMENT],
     ["-w","--warn_cyclo", GetoptLong::REQUIRED_ARGUMENT],
     ["-s","--warn_token", GetoptLong::REQUIRED_ARGUMENT],
     ["-e","--error_cyclo", GetoptLong::REQUIRED_ARGUMENT],
     ["-d","--error_token", GetoptLong::REQUIRED_ARGUMENT],
     ["-p","--parse_file", GetoptLong::REQUIRED_ARGUMENT],
     ["-i","--input_directory", GetoptLong::REQUIRED_ARGUMENT],
     ["-v","--verbose", GetoptLong::NO_ARGUMENT]
     )

  opt.each do |arg,val|
    case arg
    when "-o"
      output_dir = val
    when "-h"
      RDoc.usage('help')
    when "-f"
      formater = val
    when "-c"
      comp_state = true
    when "-t"
      comp_token = true
    when "-k"
      token_filter.limit = val.to_i
    when "-s"
      token_filter.warn = val.to_i
    when "-d"
      token_filter.error = val.to_i
    when "-y"
      state_filter.limit = val.to_i
    when "-w"
      state_filter.warn = val.to_i
    when "-e"
      state_filter.error = val.to_i
    when "-p"
      files<< val
    when "-i"
      files.concat(get_ruby_files(val))
    when "-v"
      STDOUT.puts "Verbose mode on"
      $VERBOSE = true
    end

  end
  RDoc.usage if !comp_state && !comp_token
rescue => err
  RDoc.usage
end

if formater =~ /html/i
  state_formater = StateHTMLComplexityFormater.new(STDOUT,state_filter)
  token_count_formater = HTMLTokenCounterFormater.new(STDOUT,token_filter)
else
  state_formater = ParseStateFormater.new(STDOUT,state_filter)
  token_count_formater = TokenCounterFormater.new(STDOUT,token_filter)
end

state_formater = nil if !comp_state
token_count_formater = nil if !comp_token

idx_states, idx_tokens = Saikuro.analyze(files, state_formater, token_count_formater, output_dir)

write_cyclo_index(idx_states, output_dir)
write_token_index(idx_tokens, output_dir)
end