Module: SimpleCov::CLI::Usage

Extended by:
Usage
Included in:
Usage
Defined in:
lib/simplecov/cli/usage.rb

Instance Method Summary collapse

Instance Method Details

#for(cli, command) ⇒ Object



8
9
10
11
12
13
# File 'lib/simplecov/cli/usage.rb', line 8

def for(cli, command)
  sections = text(cli).split("\n\n")
  row = sections.fetch(1).lines.find { |line| line.match?(/\A  #{Regexp.escape(command)}[ \[]/) }
  options = sections.select { |section| section_for?(section, command) }
  ["Usage: simplecov #{command} [options]", row&.strip, *options].compact.join("\n\n")
end

#heading_of(section) ⇒ Object



20
21
22
# File 'lib/simplecov/cli/usage.rb', line 20

def heading_of(section)
  section.lines.first.to_s.strip
end

#section_for?(section, command) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/simplecov/cli/usage.rb', line 15

def section_for?(section, command)
  header = heading_of(section)
  header.end_with?("options:") && header.delete_suffix("options:").split(%r{[\s/]+}).include?(command)
end

#text(cli) ⇒ Object

A method rather than a constant so its default paths resolve at call time against the active .simplecov.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/simplecov/cli/usage.rb', line 26

def text(cli)
  "    Usage: simplecov <command> [options]\n\n    Commands:\n      run <command...>          Execute <command> with SimpleCov pre-loaded\n                                (works without a test_helper hook)\n      coverage <path>           Print coverage stats for the given file\n      show <path>               Print the file's source annotated with hit counts and misses\n      report                    Print the overall summary and group totals\n      status                    Report freshness: age, commit distance, recorded tests\n      history                   Print the recorded coverage trend, a sparkline per criterion\n      badge                     Render the coverage percent as an SVG badge\n      uncovered                 List the lowest-coverage files\n      tests [<path>[:<line>]]   List recorded tests for a file or line (needs track_tests)\n      affected                  List test files touching code changed since a git ref (needs track_tests)\n      merge <files...>          Merge multiple .resultset.json files\n      diff <baseline>           Show per-file coverage delta vs baseline\n      patch                     Show coverage of the lines a change touched\n      ratchet                   Rewrite the per-file coverage baseline, only ever tightening\n      dead-code                 Cross production coverage with the report to find dead code\n      open                      Open the HTML report in the default browser\n      serve                     Serve the coverage report over HTTP\n      watch <command...>        Re-run <command> on save and live-reload the served report\n      clean                     Remove the coverage report directory\n      completions <shell>       Emit the completion script for fish, bash, or zsh\n      help                      Show this message\n      version                   Print the version (also --version / -v)\n\n    Every command answers `--help` / `-h`. Default paths follow a project's\n    `.simplecov` SimpleCov.coverage_dir (\#{cli.coverage_dir} for this run).\n\n    coverage / show / report / status / uncovered / tests / affected / diff / patch / ratchet / dead-code options:\n      --input PATH              Read from PATH instead of \#{cli.default_input}\n      --no-color                Disable colorized percentages (also honors NO_COLOR / FORCE_COLOR env)\n\n    coverage options:\n      --json                    Print the file's JSON entry verbatim\n\n    show options:\n      --uncovered-only          Print only <path>:<ranges> of the missed lines\n      --json                    Emit path, missed lines, per-line hits, and markers as JSON\n\n    report options:\n      --json                    Emit totals and group sections as JSON\n\n    status options:\n      --json                    Emit the freshness facts as a JSON object\n\n    history options:\n      --input PATH              Read from PATH instead of the coverage directory's .history.json\n      --file PATH               Follow one file's trajectory instead of the totals\n      --json                    Emit the entries (or the file's trajectory) as JSON\n      --no-color                Disable colorized deltas (also honors NO_COLOR / FORCE_COLOR env)\n\n    badge options:\n      --input PATH              Read from PATH instead of \#{cli.default_input}\n      --output PATH             Write the badge to PATH instead of stdout\n      --criterion C             line, branch, or method (default: line)\n      --label TEXT              The badge's left-side text (default: the criterion's, like \"line coverage\")\n\n    uncovered options:\n      --threshold N             Only show files below N% coverage\n      --top N                   Show at most N files (default: 10)\n      --criterion C             line, branch, or method (default: line)\n      --missing                 Append the missed line ranges to each row\n      --annotate KIND           Emit CI annotations instead of rows: github, gitlab, rdjson, azure, teamcity, or buildkite\n      --json                    Emit results as a JSON array (for CI)\n\n    tests options:\n      --redundant               List only tests whose covered lines other tests also cover\n      --json                    Emit the test ids as a JSON array\n\n    affected options:\n      --base REF                Diff against the merge base of REF and HEAD (default: origin's HEAD, else main)\n      --run <command...>        Run <command> (all args after --run) with the selection appended, or bare on a full-suite fallback, exiting with the command's status\n      --json                    Emit {full_suite, triggers, tests} as a JSON object\n\n    merge options:\n      --output PATH             Write merged resultset to PATH (default: \#{cli.default_resultset})\n      --honor-timeout           Drop entries older than merge_timeout\n      --dry-run                 Print what would be written without writing\n      -q, --quiet               Suppress the success status line\n\n    diff options:\n      --fail-on-drop            Exit non-zero when any file's coverage dropped vs baseline (deletions don't count)\n      --json                    Emit results as a JSON array (for CI)\n      --threshold N             Only show files whose absolute delta in any criterion is at least N%\n\n    patch options:\n      --base REF                Diff against the merge-base of REF for the touched lines (default: origin's HEAD, else main, or in CI the PR's target branch)\n      --minimum N               Exit non-zero when patch coverage on any measured criterion is below N%\n      --find-renames            Follow a renamed file instead of counting the moved file as all-new\n      --annotate KIND           Emit CI annotations instead of rows: github, gitlab, rdjson, azure, teamcity, or buildkite\n      --json                    Emit results as a JSON array (for CI)\n\n    dead-code options:\n      --production PATH         The production coverage file a SimpleCov::Production sink wrote (default: the project's `production_coverage`, required when none is configured)\n      --untested-in-production  Print code production runs that no test covers, instead of the dead rows\n      --json                    Emit every category (dead, possibly dead, untested in production) as JSON\n\n    ratchet options:\n      --baseline PATH           The baseline file to rewrite (default: the project's `baseline_file`, .simplecov_baseline.yml)\n      --init                    Regenerate from scratch: add entries for new files and reset every floor to the current state\n      --dry-run                 Print what would change without writing\n      --json                    Emit the summary (tightened / pruned / regressed entries) as JSON\n\n    open options:\n      --report PATH             Open PATH instead of \#{cli.default_report}\n\n    serve options:\n      --port N                  Bind to port N (default: random open port)\n      --host HOST               Bind to HOST (default: 127.0.0.1)\n\n    watch options:\n      --port N                  Bind to port N (default: random open port)\n      --host HOST               Bind to HOST (default: 127.0.0.1)\n      --interval SECONDS        Poll the tracked files this often (default: 0.5)\n      --open                    Open the served report in the default browser\n\n    clean options:\n      --dry-run                 Print what would be removed without deleting\n      -q, --quiet               Suppress status lines\n  USAGE\nend\n"