Module: SimpleCov::CLI::Status
- Extended by:
- CommandHelpers, Status
- Included in:
- Status
- Defined in:
- lib/simplecov/cli/status.rb,
lib/simplecov/cli/status/facts.rb
Defined Under Namespace
Modules: Facts
Constant Summary
CommandHelpers::STATS_ROW_FORMAT
Instance Method Summary
collapse
build_parser, command_name, common_options, error, error_nil, on_help, one?, parse_common, quiet_option, recorded_contexts, stats_row
Instance Method Details
#age_in_words(seconds) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/simplecov/cli/status.rb', line 84
def age_in_words(seconds)
return "#{seconds.round} seconds" if seconds < 90
return "#{(seconds / 60.0).round} minutes" if seconds < 5400
return "#{(seconds / 3600.0).round} hours" if seconds < 129_600
"#{(seconds / 86_400.0).round} days"
end
|
#age_suffix(age) ⇒ Object
80
81
82
|
# File 'lib/simplecov/cli/status.rb', line 80
def age_suffix(age)
" (#{age_in_words(age)} ago)" if age
end
|
#commit_words(facts) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/simplecov/cli/status.rb', line 47
def commit_words(facts)
commit = facts.fetch(:commit)
return "not recorded" unless commit.instance_of?(String)
"#{commit[0, 7]} (#{distance_words(facts.fetch(:behind))})"
end
|
#contexts_words(count) ⇒ Object
65
66
67
|
# File 'lib/simplecov/cli/status.rb', line 65
def contexts_words(count)
count ? "#{count} (track_tests)" : "none (enable track_tests to select and re-run by test)"
end
|
#distance_words(behind) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/simplecov/cli/status.rb', line 54
def distance_words(behind)
return "not in this repository's history" unless behind
return "current HEAD" if behind.zero?
"#{behind} commit#{"s" unless one?(behind)} behind HEAD"
end
|
#print_facts(facts, opts, stdout) ⇒ Object
27
28
29
30
31
|
# File 'lib/simplecov/cli/status.rb', line 27
def print_facts(facts, opts, stdout)
stdout.puts("report #{opts.fetch(:input)}")
report_lines(facts).each { |line| stdout.puts(" #{line}") }
print_resultset(facts, stdout)
end
|
#print_resultset(facts, stdout) ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/simplecov/cli/status.rb', line 69
def print_resultset(facts, stdout)
entries = facts.fetch(:resultset)
return stdout.puts("resultset none") unless entries
stdout.puts("resultset #{facts.fetch(:resultset_path)}")
entries.each do |entry|
age = entry.fetch(:age) ? "#{age_in_words(entry.fetch(:age))} ago" : "age unknown"
stdout.puts(" #{entry.fetch(:command)}: #{age}")
end
end
|
#provenance_words(facts) ⇒ Object
43
44
45
|
# File 'lib/simplecov/cli/status.rb', line 43
def provenance_words(facts)
"by simplecov #{facts.fetch(:version)} running #{facts.fetch(:command_name)}"
end
|
#report_lines(facts) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/simplecov/cli/status.rb', line 33
def report_lines(facts)
[
facts.fetch(:generated_at) && "generated #{facts.fetch(:generated_at)}#{age_suffix(facts.fetch(:age))}",
provenance_words(facts),
"commit #{commit_words(facts)}",
(totals_words(facts.fetch(:totals)) unless facts.fetch(:totals).empty?),
"tests recorded: #{contexts_words(facts.fetch(:contexts))}"
].compact
end
|
#run(args, stdout:, stderr:) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/simplecov/cli/status.rb', line 17
def run(args, stdout:, stderr:)
opts, = parse_common(args)
document = CoverageFile.load_document(opts.fetch(:input), command: "status", stderr: stderr)
return 1 unless document
facts = Facts.gather(document, CLI.default_resultset)
opts.fetch(:json) ? stdout.puts(JSON.pretty_generate(facts)) : print_facts(facts, opts, stdout)
0
end
|
#totals_words(totals) ⇒ Object
61
62
63
|
# File 'lib/simplecov/cli/status.rb', line 61
def totals_words(totals)
totals.map { |name, percent| "#{name} #{format("%.2f%%", percent)}" }.join(", ")
end
|