Class: Cyclomagic::CyclomagicCMDLineRunner

Inherits:
Object
  • Object
show all
Includes:
ResultIndexGenerator
Defined in:
lib/cyclomagic.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(input_path) ⇒ Object



1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/cyclomagic.rb', line 1042

def get_ruby_files(input_path)
  files = Array.new
  input_path.split("|").each do |path|
  Find.find(path.strip) do |f|
      files << f if !FileTest.directory?(f) && f =~ /\.rb$/
    end
  end
  files
end

#runObject



1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
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
# File 'lib/cyclomagic.rb', line 1052

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 = Cyclomagic.analyze(files,
                                           state_formater,
                                           token_count_formater,
                                           output_dir)

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