Module: RSpecTracer::CLI Private

Defined in:
lib/rspec_tracer/cli.rb,
lib/rspec_tracer/cli/doctor.rb,
lib/rspec_tracer/cli/explain.rb,
lib/rspec_tracer/cli/cache_info.rb,
lib/rspec_tracer/cli/cache_clear.rb,
lib/rspec_tracer/cli/report_open.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Internal CLI β€” see RSpecTracer for the user-facing surface.

Defined Under Namespace

Modules: CacheClear, CacheInfo, Doctor, Explain, ReportOpen

Constant Summary collapse

SUB_COMMANDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Internal constant.

{
  'doctor' => 'Doctor',
  'cache:info' => 'CacheInfo',
  'cache:clear' => 'CacheClear',
  'report:open' => 'ReportOpen',
  'explain' => 'Explain'
}.freeze

Class Method Summary collapse

Class Method Details

.dispatch(args, stdout:, stderr:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal helper for the tracer pipeline.



57
58
59
60
61
62
63
64
# File 'lib/rspec_tracer/cli.rb', line 57

def self.dispatch(args, stdout:, stderr:)
  sub = args.shift
  klass_name = SUB_COMMANDS[sub]
  return unknown_sub_command(sub, stderr) if klass_name.nil?

  load_sub_command(klass_name)
  RSpecTracer::CLI.const_get(klass_name).run(args, stdout: stdout, stderr: stderr)
end

.load_sub_command(klass_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal helper for the tracer pipeline.



105
106
107
108
109
110
111
112
113
114
# File 'lib/rspec_tracer/cli.rb', line 105

def self.load_sub_command(klass_name)
  filename = klass_name.gsub(/([A-Z])/) { |m| "_#{m.downcase}" }.sub(/^_/, '')
  require_relative "cli/#{filename}"
rescue LoadError => e
  # LoadError isn't a StandardError, so the outer `rescue StandardError`
  # in `.run` wouldn't catch it. Re-raise as StandardError so the dispatch
  # path stays uniform: any sub-command resolution failure prints
  # `rspec-tracer: <class>: <message>` and exits 1.
  raise StandardError, "could not load sub-command #{klass_name.inspect}: #{e.message}"
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal helper for the tracer pipeline.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rspec_tracer/cli.rb', line 76

def self.print_top_level_help(stdout)
  stdout.puts <<~HELP
    Usage: rspec-tracer <sub-command> [options]

    Sub-commands:
      doctor          Diagnose rspec-tracer config + environment.
      cache:info      Show cache size, last run timestamp, and example counts.
      cache:clear     Remove cache, coverage, and report directories.
      report:open     Open the HTML report in the default browser.
      explain <id>    Show why an example is scheduled to run or skip.

    Options:
      -h, --help      Print this help message.
      -v, --version   Print rspec-tracer version.

    Run `rspec-tracer <sub-command> --help` for sub-command options.
  HELP
  0
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal helper for the tracer pipeline.



98
99
100
101
# File 'lib/rspec_tracer/cli.rb', line 98

def self.print_version(stdout)
  stdout.puts "rspec-tracer #{RSpecTracer::VERSION}"
  0
end

.run(argv, stdout: $stdout, stderr: $stderr) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

CLI entry. Called by β€˜bin/rspec-tracer` with `ARGV`. Wraps every sub-command in a top-level rescue so the binary always exits with a meaningful integer status (0 / 1) instead of a backtrace.

Parameters:

  • argv (Array<String>)

    command-line arguments (excluding the program name)

  • stdout (IO) (defaults to: $stdout)

    stream for normal output (default β€˜$stdout`)

  • stderr (IO) (defaults to: $stderr)

    stream for errors / diagnostics (default β€˜$stderr`)

Returns:

  • (Integer)

    exit status (0 = success, 1 = failure)



44
45
46
47
48
49
50
51
52
53
# File 'lib/rspec_tracer/cli.rb', line 44

def self.run(argv, stdout: $stdout, stderr: $stderr)
  args = argv.dup
  return print_top_level_help(stdout) if args.empty? || %w[-h --help help].include?(args.first)
  return print_version(stdout) if %w[-v --version].include?(args.first)

  dispatch(args, stdout: stdout, stderr: stderr)
rescue StandardError => e
  stderr.puts "rspec-tracer: #{e.class}: #{e.message}"
  1
end

.unknown_sub_command(sub, stderr) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal helper for the tracer pipeline.



68
69
70
71
72
# File 'lib/rspec_tracer/cli.rb', line 68

def self.unknown_sub_command(sub, stderr)
  stderr.puts "rspec-tracer: unknown sub-command #{sub.inspect}"
  stderr.puts "  available: #{SUB_COMMANDS.keys.join(', ')}"
  1
end