Module: SimpleCov::CLI
- Extended by:
- CLI
- Included in:
- CLI
- Defined in:
- lib/simplecov/cli.rb,
lib/simplecov/cli/git.rb,
lib/simplecov/cli/run.rb,
lib/simplecov/cli/diff.rb,
lib/simplecov/cli/open.rb,
lib/simplecov/cli/show.rb,
lib/simplecov/cli/badge.rb,
lib/simplecov/cli/clean.rb,
lib/simplecov/cli/merge.rb,
lib/simplecov/cli/patch.rb,
lib/simplecov/cli/serve.rb,
lib/simplecov/cli/tests.rb,
lib/simplecov/cli/usage.rb,
lib/simplecov/cli/watch.rb,
lib/simplecov/cli/report.rb,
lib/simplecov/cli/status.rb,
lib/simplecov/cli/dotfile.rb,
lib/simplecov/cli/history.rb,
lib/simplecov/cli/ratchet.rb,
lib/simplecov/cli/affected.rb,
lib/simplecov/cli/coverage.rb,
lib/simplecov/cli/badge/svg.rb,
lib/simplecov/cli/dead_code.rb,
lib/simplecov/cli/real_path.rb,
lib/simplecov/cli/uncovered.rb,
lib/simplecov/cli/show/sweep.rb,
lib/simplecov/cli/annotations.rb,
lib/simplecov/cli/completions.rb,
lib/simplecov/cli/diff/output.rb,
lib/simplecov/cli/patch/output.rb,
lib/simplecov/cli/status/facts.rb,
lib/simplecov/cli/watch/poller.rb,
lib/simplecov/cli/coverage_file.rb,
lib/simplecov/cli/watch/session.rb,
lib/simplecov/cli/history/output.rb,
lib/simplecov/cli/ratchet/output.rb,
lib/simplecov/cli/show/annotator.rb,
lib/simplecov/cli/watch/narrator.rb,
lib/simplecov/cli/affected/runner.rb,
lib/simplecov/cli/command_helpers.rb,
lib/simplecov/cli/watch/test_plan.rb,
lib/simplecov/cli/dead_code/output.rb,
lib/simplecov/cli/tests/redundancy.rb,
lib/simplecov/cli/uncovered/misses.rb,
lib/simplecov/cli/watch/live_report.rb,
lib/simplecov/cli/affected/selection.rb,
lib/simplecov/cli/completions/scripts.rb,
lib/simplecov/cli/patch/changed_lines.rb,
lib/simplecov/cli/serve/report_preparer.rb,
lib/simplecov/cli/affected/changed_files.rb,
lib/simplecov/cli/serve/static_file_handler.rb
Overview
Lightweight command-line front-end. Read-only subcommands consume
JSONFormatter output, which the bundled HTMLFormatter already drops
alongside the HTML, so no runtime hooking is needed for those. Default
paths follow the project's .simplecov coverage_dir setting when one is
present.
Defined Under Namespace
Modules: Affected, Annotations, Badge, Clean, CommandHelpers, Completions, Coverage, CoverageFile, DeadCode, Diff, Dotfile, Git, History, JDKRealPath, Merge, Open, Patch, Ratchet, Report, Run, Serve, Show, Status, Tests, Uncovered, Usage, Watch
Constant Summary collapse
- COMMANDS =
{ "coverage" => Coverage, "show" => Show, "run" => Run, "open" => Open, "report" => Report, "status" => Status, "history" => History, "uncovered" => Uncovered, "tests" => Tests, "affected" => Affected, "merge" => Merge, "diff" => Diff, "patch" => Patch, "ratchet" => Ratchet, "dead-code" => DeadCode, "serve" => Serve, "watch" => Watch, "badge" => Badge, "clean" => Clean, "completions" => Completions }.freeze
- REAL_PATHS =
simplecov:enable
RUBY_ENGINE.eql?("jruby") ? JDKRealPath : File
Instance Method Summary collapse
- #color_enabled?(opts, stream) ⇒ Boolean
-
#coverage_dir ⇒ Object
Resolved once per process, by walking up from cwd for a
.simplecovand loading it withSimpleCov.startneutered so it can't trigger tracking just because we asked it for a config value. - #default_input ⇒ Object
- #default_report ⇒ Object
- #default_resultset ⇒ Object
-
#dispatch(handler, command, rest, stdout:, stderr:) ⇒ Object
One rescue covers every subcommand's OptionParser, so a typo'd flag becomes a one-line error and exit status 1 instead of a backtrace.
- #run(argv, stdout: $stdout, stderr: $stderr) ⇒ Object
- #usage ⇒ Object
Instance Method Details
#color_enabled?(opts, stream) ⇒ Boolean
74 75 76 77 78 |
# File 'lib/simplecov/cli.rb', line 74 def color_enabled?(opts, stream) return false if opts[:no_color] Color.enabled?(stream) end |
#coverage_dir ⇒ Object
Resolved once per process, by walking up from cwd for a .simplecov and
loading it with SimpleCov.start neutered so it can't trigger tracking
just because we asked it for a config value.
66 67 68 |
# File 'lib/simplecov/cli.rb', line 66 def coverage_dir @coverage_dir ||= Dotfile.coverage_dir end |
#default_input ⇒ Object
70 71 72 |
# File 'lib/simplecov/cli.rb', line 70 def default_input File.join(coverage_dir, "coverage.json") end |
#default_report ⇒ Object
80 81 82 |
# File 'lib/simplecov/cli.rb', line 80 def default_report File.join(coverage_dir, "index.html") end |
#default_resultset ⇒ Object
84 85 86 |
# File 'lib/simplecov/cli.rb', line 84 def default_resultset File.join(coverage_dir, ".resultset.json") end |
#dispatch(handler, command, rest, stdout:, stderr:) ⇒ Object
One rescue covers every subcommand's OptionParser, so a typo'd flag becomes a one-line error and exit status 1 instead of a backtrace.
101 102 103 104 105 106 107 108 109 |
# File 'lib/simplecov/cli.rb', line 101 def dispatch(handler, command, rest, stdout:, stderr:) handler.run(rest, stdout: stdout, stderr: stderr) rescue CommandHelpers::HelpRequested stdout.puts(Usage.for(self, command)) 0 rescue OptionParser::ParseError => e stderr.puts("simplecov #{command}: #{e} (run `simplecov help` for usage)") 1 end |
#run(argv, stdout: $stdout, stderr: $stderr) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/simplecov/cli.rb', line 88 def run(argv, stdout: $stdout, stderr: $stderr) command, *rest = argv handler = COMMANDS[command] return dispatch(handler, command, rest, stdout: stdout, stderr: stderr) if handler return stdout.puts(usage) || 0 if [nil, "help", "--help", "-h"].include?(command) return stdout.puts("simplecov #{VERSION}") || 0 if %w[version --version -v].include?(command) stderr.puts("simplecov: unknown command #{command.inspect}", usage) 1 end |