lib/attractor/cli.rb in attractor-0.1.2 vs lib/attractor/cli.rb in attractor-0.2.0

- old
+ new

@@ -7,23 +7,34 @@ module Attractor # contains methods implementing the CLI class CLI < Thor desc 'calc', 'Calculates churn and complexity for all ruby files in current directory' option :file_prefix, aliases: :p + option :watch, aliases: :w, type: :boolean def calc - puts 'Calculated churn and complexity' - puts - puts "file_path#{' ' * 53}complexity churn" - puts '-' * 80 - Attractor::Calculator.output_console(file_prefix: options[:file_prefix]) + if options[:watch] + puts 'Listening for file changes...' + Attractor::ConsoleReporter.new(file_prefix: options[:file_prefix]).watch + else + Attractor::ConsoleReporter.new(file_prefix: options[:file_prefix]).report + end end desc 'report', 'Generates an HTML report' option :format, aliases: :f, default: 'html' option :file_prefix, aliases: :p + option :watch, aliases: :w, type: :boolean def report - puts 'Generating an HTML report' - Attractor::Calculator.report(format: options[:format], file_prefix: options[:file_prefix]) - puts "Generated HTML report at #{File.expand_path './attractor_output/index.html'}" + if options[:watch] + puts 'Listening for file changes...' + Attractor::HtmlReporter.new(file_prefix: options[:file_prefix]).watch + else + case options[:format] + when 'html' + Attractor::HtmlReporter.new(file_prefix: options[:file_prefix]).report + else + Attractor::HtmlReporter.new(file_prefix: options[:file_prefix]).report + end + end end end end