Class: SaikuroCMDLineRunner

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

Overview

Really ugly command line runner stuff here for now

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

#get_ruby_files(path) ⇒ Object



1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
# File 'lib/saikuro.rb', line 1082

def get_ruby_files(path)
  files = Array.new
  Find.find(path) do |f|
    if !FileTest.directory?(f)
	if f =~ /rb$/
 files<< f
	end
    end
  end
  files
end

#runObject



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/saikuro.rb', line 1094

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