Class: Rigor::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/cli.rb,
lib/rigor/cli/type_of_command.rb,
lib/rigor/cli/type_of_renderer.rb,
lib/rigor/cli/type_scan_report.rb,
lib/rigor/cli/type_scan_command.rb,
lib/rigor/cli/type_scan_renderer.rb

Overview

The CLI class is a dispatcher: each ‘run_*` method delegates to a command-specific class once the command grows beyond a few lines (see TypeOfCommand). The class-length budget is intentionally relaxed here so dispatch wiring can live alongside still-inlined commands.

Defined Under Namespace

Classes: Report, TypeOfCommand, TypeOfRenderer, TypeScanCommand, TypeScanRenderer

Constant Summary collapse

EXIT_USAGE =

rubocop:disable Metrics/ClassLength

64
HANDLERS =
{
  "check" => :run_check,
  "init" => :run_init,
  "type-of" => :run_type_of,
  "type-scan" => :run_type_scan
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CLI.



31
32
33
34
35
# File 'lib/rigor/cli.rb', line 31

def initialize(argv, out:, err:)
  @argv = argv
  @out = out
  @err = err
end

Class Method Details

.start(argv = ARGV, out: $stdout, err: $stderr) ⇒ Object



27
28
29
# File 'lib/rigor/cli.rb', line 27

def self.start(argv = ARGV, out: $stdout, err: $stderr)
  new(argv.dup, out: out, err: err).run
end

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rigor/cli.rb', line 37

def run
  command = @argv.shift

  case command
  when nil, "help", "-h", "--help"
    @out.puts(help)
    0
  when "version", "-v", "--version"
    @out.puts("rigor #{Rigor::VERSION}")
    0
  else
    dispatch(command)
  end
rescue OptionParser::ParseError => e
  @err.puts(e.message)
  EXIT_USAGE
end