Class: Rigor::CLI::ExplainCommand

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

Overview

Executes ‘rigor explain <rule>`. Prints the catalog entry for one canonical rule id, a legacy alias, or a family wildcard (`call`, `flow`, `assert`, `dump`, `def`).

Without arguments lists every rule’s id and one-line summary.

The command is read-only: no parser, no analyzer, no I/O beyond the rendered catalog. Useful when a user sees a diagnostic in the editor and wants to know what the rule means without leaving the terminal.

Constant Summary collapse

USAGE =
"Usage: rigor explain [options] [<rule>]"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ExplainCommand.



23
24
25
26
27
# File 'lib/rigor/cli/explain_command.rb', line 23

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

Instance Method Details

#runInteger

Returns CLI exit status.

Returns:

  • (Integer)

    CLI exit status.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rigor/cli/explain_command.rb', line 30

def run
  options = parse_options

  if @argv.empty?
    render_index(options.fetch(:format))
    return 0
  end

  token = @argv.shift
  entries = Analysis::RuleCatalog.resolve(token)
  if entries.empty?
    @err.puts("Unknown rule: #{token}")
    @err.puts("Run `rigor explain` with no arguments to list every rule.")
    return CLI::EXIT_USAGE
  end

  render_entries(entries, options.fetch(:format))
  0
end