Class: SaikuroCMDLineRunner
- Inherits:
-
Object
- Object
- SaikuroCMDLineRunner
- Includes:
- ResultIndexGenerator
- Defined in:
- lib/saikuro.rb
Overview
Really ugly command line runner stuff here for now
Instance Method Summary collapse
- #get_ruby_files(path) ⇒ Object
-
#initialize(args = "-h") ⇒ SaikuroCMDLineRunner
constructor
A new instance of SaikuroCMDLineRunner.
- #parse(args) ⇒ Object
- #run! ⇒ Object
Methods included from ResultIndexGenerator
#list_analyzed_files, #print_summary_table_rows, #summarize_errors_and_warnings, #write_cyclo_index, #write_index, #write_token_index
Constructor Details
#initialize(args = "-h") ⇒ SaikuroCMDLineRunner
Returns a new instance of SaikuroCMDLineRunner.
1159 1160 1161 1162 1163 |
# File 'lib/saikuro.rb', line 1159 def initialize(args="-h") @options = parse(args) ("No input files specified") if @options[:files].empty? ('Please choose token or cyclo mode') if !@options[:comp_state] && !@options[:comp_token] end |
Instance Method Details
#get_ruby_files(path) ⇒ Object
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 |
# File 'lib/saikuro.rb', line 1062 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 |
#parse(args) ⇒ Object
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 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 |
# File 'lib/saikuro.rb', line 1074 def parse(args) # Set up reasonable defaults for options. = {} [:files] = Array.new [:output_dir] = './' [:formater] = 'html' [:state_filter] = Filter.new(5) [:token_filter] = Filter.new(10, 25, 50) [:comp_state] = false [:comp_token] = false # Parse the command-line arguments. @opts = OptionParser.new do |opts| opts. = 'Usage: saikuro [ -h ] [-o output_directory] [-f type] [ -c, -t ] [ -y, -w, -e, -k, -s, -d - number ] ( -p file | -i directory )' opts.separator '' opts.separator 'Specific options:' opts.on('-v', '--verbose', 'Verbose output.') do [:verbose] = true $VERBOSE = true end opts.on('-o', '--output_directory DIRECTORY', 'A directory to ouput the results in. The current directory is used if this option is not passed.') do |output_dir| [:output_dir] = output_dir end opts.on('-f', '--formater (html | text)', 'The format to output the results in. The default is html') do |formater| [:formater] = formater end opts.on('-c', '--cyclo', 'Compute the cyclomatic complexity of the input.') do [:comp_state] = true end opts.on('-t', '--token', 'Count the number of tokens per line of the input.') do [:comp_token] = true end opts.on('-y', '--filter_cyclo NUMBER', 'Filter the output to only include methods whose cyclomatic complexity are greater than the passed number.') do |number| [:state_filter].limit = number.to_i end opts.on('-w', '--warn_cyclo NUMBER', 'Highlight with a warning methods whose cyclomatic complexity are greather than or equal to the passed number.') do |number| [:state_filter].warn = number.to_i end opts.on('-e', '--error_cyclo NUMBER', 'Highlight with a error methods whose cyclomatic complexity are greather than or equal to the passed number.') do |number| [:state_filter].error = number.to_i end opts.on('-k', '--filter_token NUMBER', 'Filter the output to only include lines whose token count are greater than the passed number.') do |number| [:token_filter].limit = number.to_i end opts.on('-s', '--warn_token NUMBER', 'Highlight with a warning lines whose token count are greather than or equal to the passed number.') do |number| [:token_filter].warn = number.to_i end opts.on('-d', '--error_token NUMBER', 'Highlight with a error lines whose token count are greather than or equal to the passed number.') do |number| [:token_filter].error = number.to_i end opts.on('-p', '--parse_file FILE', 'A file to use as input.') do |file| [:files] << file end opts.on('-i', '--input_directory DIRECTORY', 'All ruby files found recursively inside the directory are passed as input.') do |directory| [:files].concat(get_ruby_files(directory)) end opts.separator '' # No argument, shows at tail. This will print an options summary. # Try it and see! opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end @opts.parse! args end |
#run! ⇒ Object
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 |
# File 'lib/saikuro.rb', line 1165 def run! if @options[:formater] =~ /html/i state_formater = StateHTMLComplexityFormater.new(STDOUT,@options[:state_filter]) token_count_formater = HTMLTokenCounterFormater.new(STDOUT,@options[:token_filter]) else state_formater = ParseStateFormater.new(STDOUT,@options[:state_filter]) token_count_formater = TokenCounterFormater.new(STDOUT,@options[:token_filter]) end state_formater = nil if !@options[:comp_state] token_count_formater = nil if !@options[:comp_token] idx_states, idx_tokens = Saikuro.analyze(@options[:files], state_formater, token_count_formater, @options[:output_dir]) write_cyclo_index(idx_states, @options[:output_dir]) write_token_index(idx_tokens, @options[:output_dir]) end |