bin/excellent in excellent-1.7.2 vs bin/excellent in excellent-2.0.0
- old
+ new
@@ -6,13 +6,16 @@
options = {}
optparse = OptionParser.new do |opt|
opt.banner = 'Usage: excellent [OPTIONS] <PATH1> [<PATH2> ...]'
- opt.on('--output', '-o [FILE]', 'Write HTML output to [FILE].') do |target|
+ opt.on('--output', '-o [FILE]', 'Write HTML output to [FILE]') do |target|
options[:output] = target
end
+ opt.on('--checks', 'Show a list of the enabled checks and their configuraton values') do |target|
+ options[:print_checks] = true
+ end
opt.on_tail('--help', '-h', 'Help') do
puts optparse
exit
end
opt.on_tail('--version', '-v', 'Version') do
@@ -22,30 +25,64 @@
end
optparse.parse!
target = options[:output]
-paths = ARGV.dup
-
-if paths.empty?
- puts "\n You must specify one or more directories to analyse, e.g.:\n"
- puts "\n excellent lib/\n\n"
- exit 1
-end
-
if target
begin
fileio = File.open(target, 'w+')
formatter = Simplabs::Excellent::Formatters::Html.new(fileio)
rescue Errno::ENOENT
- puts "\n #{target} cannot be opened for writing. Specify a file name like so:\n"
- puts "\n excellent -o excellent.html lib/\n\n"
+ puts "\n **#{target} cannot be opened for writing. Specify a file name like so:\n"
+ puts "\n excellent -o excellent.html lib/\n\n"
end
else
formatter = Simplabs::Excellent::Formatters::Text.new
end
-excellent = Simplabs::Excellent::Runner.new
+custom_config = {}
+config_file = File.join(Dir.pwd, '.excellent.yml')
+if File.exists?(config_file)
+ require 'yaml'
+ begin
+ custom_config = YAML.load(File.open(config_file)) || {}
+ config_valid = custom_config.is_a?(Hash) && custom_config.all? do |key, value|
+ key.is_a?(String) || key.is_a?(Symbol)
+ end
+ rescue Exception
+ config_valid = false
+ end
+ unless config_valid
+ puts "\n ** The configuration in #{config_file} is not valid!\n\n"
+ puts " Please make sure you specify a hash with check names as keys and hashes or truthy/falsy values as hash values, e.g.:\n\n"
+ puts " AbcMetricMethodCheck:"
+ puts " false"
+ puts " ClassLineCountCheck:"
+ puts " threshold: 10"
+ puts "\n\n"
+ exit 1
+ end
+end
+
+excellent = Simplabs::Excellent::Runner.new(custom_config)
+
+if options[:print_checks]
+ puts "\n Configured Checks\n\n"
+ excellent.checks.each do |check|
+ puts " #{check.class.name.gsub('Simplabs::Excellent::Checks::', '')}"
+ check.options.each do |key, value|
+ puts " #{key}: #{value}"
+ end
+ end
+ exit 0
+end
+
+paths = ARGV.dup
+if paths.empty?
+ puts "\n **You must specify one or more directories to analyse, e.g.:\n"
+ puts "\n excellent lib/\n\n"
+ exit 1
+end
begin
excellent.check_paths(paths, formatter)
rescue ArgumentError
puts "\n** Excellent cannot find the paths specified!\n\n"