Class: SorbetProgress::CLI

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/sorbet_progress/cli.rb

Overview

Parses the provided metrics file and prints a report.

Constant Summary collapse

USAGE =
<<~EOS
  Usage: sorbet_progress [--reporter name] /path/to/sorbet_metrics.json
  Reporters: bar_chart, verbose
EOS

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sorbet_progress/cli.rb', line 24

def initialize(argv)
  # TODO: use an actual CLI args parser, like optparse or trollop
  case argv.length
  when 1
    @path = argv.first
    @reporter_name = "verbose"
  when 3
    @path = argv.last
    @reporter_name = argv[1]
  else
    raise Error.new(1, USAGE)
  end
end

Instance Method Details

#runObject



39
40
41
42
43
44
# File 'lib/sorbet_progress/cli.rb', line 39

def run
  metrics = parse(@path)
  calculator = Calculator.new(metrics)
  reporter = reporter_class(@reporter_name).new(calculator)
  puts reporter.report
end