lib/polytrix/command/list.rb in polytrix-0.1.2 vs lib/polytrix/command/list.rb in polytrix-0.1.3

- old
+ new

@@ -1,53 +1,64 @@ +require 'polytrix/reporters' module Polytrix module Command class List < Polytrix::Command::Base - def call - # Logging.mdc['command'] = 'list' + include Polytrix::Reporters + def call setup - tests = parse_subcommand(args.first) + @reporter = Polytrix::Reporters.reporter(options[:format], shell) + tests = parse_subcommand(args.pop) - table = [ - [ - colorize('Suite', :green), colorize('Scenario', :green), - colorize('Implementor', :green), colorize('Status', :green) - ] - ] + table = [header_row] table += tests.map do | challenge | - [ - color_pad(challenge.suite), - color_pad(challenge.name), - color_pad(challenge.implementor.name), - format_last_action(challenge) - ] + row(challenge) end - shell.print_table table + print_table(table) end private + def header_row + row = [] + row << colorize('Test ID', :green) + row << colorize('Suite', :green) + row << colorize('Scenario', :green) + row << colorize('Implementor', :green) + row << colorize('Status', :green) + row << colorize('Source', :green) if options[:source] + row + end + + def row(challenge) + row = [] + row << color_pad(challenge.slug) + row << color_pad(challenge.suite) + row << color_pad(challenge.name) + row << color_pad(challenge.implementor.name) + row << format_status(challenge) + if options[:source] + source_file = challenge.absolute_source_file ? relativize(challenge.absolute_source_file, Dir.pwd) : colorize('<No code sample>', :red) + row << source_file + end + row + end + def print_table(*args) - shell.print_table(*args) + @reporter.print_table(*args) end def colorize(string, *args) - shell.set_color(string, *args) + return string unless @reporter.respond_to? :set_color + @reporter.set_color(string, *args) end def color_pad(string) string + colorize('', :white) end - def format_last_action(challenge) - case challenge.last_action - when 'clone' then colorize('Cloned', :cyan) - when 'bootstrap' then colorize('Bootstrapped', :magenta) - when 'exec' then colorize('Executed', :blue) - when 'verify' then colorize("Verified (x#{challenge.validations.count})", :yellow) - when nil then colorize('<Not Found>', :red) - else colorize("<Unknown (#{challenge.last_action})>", :white) - end + def format_status(challenge) + colorize(challenge.status_description, challenge.status_color) end end end end