Skip to content

Commit

Permalink
+ Added --timeout option. Defaults to 10 seconds.
Browse files Browse the repository at this point in the history
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
zenspider committed Feb 13, 2013
1 parent 59a6b1c commit b1c4baf
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/flay.rb
Expand Up @@ -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|
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -251,6 +261,8 @@ def summary
end

def report prune = nil
analyze

puts "Total score (lower is better) = #{self.total}"
puts

Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit b1c4baf

Please sign in to comment.