Class: Rutidy::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rutidy/cli.rb

Overview

rutidy's two modes, matching gomeleon's own "wrap the CLI, or read its JSON report directly" duality:

rutidy                  # wraps `rspec` with no args
rutidy spec/foo_spec.rb # wraps `rspec spec/foo_spec.rb`
rutidy -fd spec/        # style flag + wrapped invocation
rutidy report.json      # formats an existing report file directly
rspec ... | rutidy -fs  # reads a piped report from stdin

A single argument ending in .json is treated as an existing report to render; anything else on the command line is handed straight through to rspec (with Formatter inserted via --require/--format). Piped stdin with no arguments at all is read as a report too, the same way gorderly's openInput treats piped stdin vs. shelling out to go test itself.

Constant Summary collapse

STYLE_ALIASES =
{
  "documentation" => :fd,
  "spec" => :fs,
  "vitest" => :fv
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, out:, err:, stdin:) ⇒ CLI

Returns a new instance of CLI.



35
36
37
38
39
40
41
42
# File 'lib/rutidy/cli.rb', line 35

def initialize(argv, out:, err:, stdin:)
  @argv = argv.dup
  @out = out
  @err = err
  @stdin = stdin
  @style = :classic
  @color = @out.respond_to?(:tty?) && @out.tty? && ENV["NO_COLOR"].nil?
end

Class Method Details

.run(argv, out: $stdout, err: $stderr, stdin: $stdin) ⇒ Object



31
32
33
# File 'lib/rutidy/cli.rb', line 31

def self.run(argv, out: $stdout, err: $stderr, stdin: $stdin)
  new(argv, out: out, err: err, stdin: stdin).run
end

Instance Method Details

#runObject



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

def run
  if wants_version?
    @out.puts("rutidy #{Rutidy::VERSION}")
    return 0
  end

  rest = parse_flags!
  examples = load_examples(rest)
  return 1 if examples.nil?

  Render.call(examples, style: @style, out: @out, color: @color).positive? ? 1 : 0
end