Class: Rigor::CLI::ExplainCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/rigor/cli/explain_command.rb,
sig/rigor/cli/explain_command.rbs

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

#initializeExplainCommand

Returns a new instance of ExplainCommand.

Parameters:

  • argv: (Object)
  • out: (Object)
  • err: (Object)


2
# File 'sig/rigor/cli/explain_command.rbs', line 2

def initialize: (argv: untyped, out: untyped, err: untyped) -> void

Instance Method Details

#runInteger

Returns CLI exit status.

Returns:

  • (Integer)

    CLI exit status.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rigor/cli/explain_command.rb', line 22

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