Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ Added --timeout option. Defaults to 10 seconds.

Flay.parse_options now has an args argument. Defaults to ARGV. Good for testing.
+ Added ability for plugins to define options_<pluginname> method to extend options.
+ Moved #analyze down to #report. #process only processes, nothing more.
+ Sort output for more stable reporting. Better for diffing against, my dear.

[git-p4: depot-paths = "//src/flay/dev/": change = 8205]
  • Loading branch information...
commit b1c4baf659edace56ea1885fa1b4f31fadbef35c 1 parent 59a6b1c
@zenspider zenspider authored
Showing with 19 additions and 7 deletions.
  1. +19 −7 lib/flay.rb
View
26 lib/flay.rb
@@ -23,10 +23,11 @@ def self.default_options
:mass => 16,
:summary => false,
:verbose => false,
+ :timeout => 10,
}
end
- def self.parse_options
+ def self.parse_options args = ARGV
options = self.default_options
OptionParser.new do |opts|
@@ -46,7 +47,8 @@ def self.parse_options
abort "--fuzzy is no longer supported. Sorry. It sucked."
end
- opts.on('-m', '--mass MASS', Integer, "Sets mass threshold") do |m|
+ opts.on('-m', '--mass MASS', Integer,
+ "Sets mass threshold (default = #{options[:mass]})") do |m|
options[:mass] = m.to_i
end
@@ -62,13 +64,23 @@ def self.parse_options
options[:summary] = true
end
+ opts.on('-t', '--timeout TIME', Integer,
+ "Set the timeout. (default = #{options[:timeout]})") do |t|
+ options[:timeout] = t.to_i
+ end
+
extensions = ['rb'] + Flay.load_plugins
opts.separator ""
opts.separator "Known extensions: #{extensions.join(', ')}"
+ extensions.each do |meth|
+ msg = "options_#{meth}"
+ send msg, opts, options if self.respond_to?(msg)
+ end
+
begin
- opts.parse!
+ opts.parse! args
rescue => e
abort "#{e}\n\n#{opts}"
end
@@ -155,8 +167,6 @@ def process(*files) # TODO: rename from process - should act as SexpProcessor
warn " skipping #{file}: #{e.message}"
end
end
-
- analyze
end
def analyze
@@ -172,7 +182,7 @@ def analyze
def process_rb file
begin
- RubyParser.new.process(File.binread(file), file)
+ RubyParser.new.process(File.binread(file), file, option[:timeout])
rescue Timeout::Error
warn "TIMEOUT parsing #{file}. Skipping."
end
@@ -251,6 +261,8 @@ def summary
end
def report prune = nil
+ analyze
+
puts "Total score (lower is better) = #{self.total}"
puts
@@ -282,7 +294,7 @@ def report prune = nil
puts "%d) %s code found in %p (mass%s = %d)" %
[count, match, node.first, bonus, mass]
- nodes.each_with_index do |x, i|
+ nodes.sort_by { |x| [x.file, x.line] }.each_with_index do |x, i|
if option[:diff] then
c = (?A.ord + i).chr
puts " #{c}: #{x.file}:#{x.line}"
Please sign in to comment.
Something went wrong with that request. Please try again.