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/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/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, 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

Instance Method Summary collapse

Instance Method Details

#color_enabled?(opts, stream) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/simplecov/cli.rb', line 73

def color_enabled?(opts, stream)
  return false if opts[:no_color]

  Color.enabled?(stream)
end

#coverage_dirObject

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.



65
66
67
# File 'lib/simplecov/cli.rb', line 65

def coverage_dir
  @coverage_dir ||= Dotfile.coverage_dir
end

#default_inputObject



69
70
71
# File 'lib/simplecov/cli.rb', line 69

def default_input
  File.join(coverage_dir, "coverage.json")
end

#default_reportObject



79
80
81
# File 'lib/simplecov/cli.rb', line 79

def default_report
  File.join(coverage_dir, "index.html")
end

#default_resultsetObject



83
84
85
# File 'lib/simplecov/cli.rb', line 83

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.



100
101
102
103
104
105
106
107
108
# File 'lib/simplecov/cli.rb', line 100

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



87
88
89
90
91
92
93
94
95
96
# File 'lib/simplecov/cli.rb', line 87

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

#usageObject



110
111
112
# File 'lib/simplecov/cli.rb', line 110

def usage
  Usage.text(self)
end