Class: Rigor::CLI::SigGenCommand

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

Overview

Executes the rigor sig-gen command — ADR-14 slices 1–3.

Walks the given paths (or configuration.paths when none are supplied), classifies every reachable instance method via SigGen::Generator, and either prints the resulting RBS skeletons / unified-style diffs (--print, --diff; slice 1) or writes them to the project signature tree via SigGen::Writer (--write; slice 2).

--write follows the established Ruby community convention: lib/foo/bar.rbsig/foo/bar.rbs. New methods are inserted into the matching class declaration just before its closing end; new classes are appended to the file; non-existent target files are created. User-authored declarations are NEVER replaced unless --overwrite is set AND the candidate is a tighter-return.

Parameter policy defaults to untyped. --params=observed (slice 3) opts in to caller-side observation harvesting: the ObservationCollector walks --observe=PATH... (default spec/ when no flag is given AND a spec/ directory exists), unions per-position arg types, and the generator emits the union per ADR-5 clause 2. --params=observed-strict stays reserved-but-inert until the capability-role catalog ships (rejected with a usage error so the surface stays stable).

Constant Summary collapse

USAGE =
"Usage: rigor sig-gen [options] [paths]"
VALID_MODES =
%w[print diff write].freeze
VALID_PARAM_POLICIES =
%w[untyped observed observed-strict].freeze
VALID_FORMATS =
%w[text json].freeze

Instance Method Summary collapse

Constructor Details

#initializeSigGenCommand

Returns a new instance of SigGenCommand.

Parameters:

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


2
# File 'sig/rigor/cli/sig_gen_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.



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

def run
  options = parse_options
  return CLI::EXIT_USAGE if options.nil?

  configuration = Configuration.load(options.fetch(:config))
  paths = @argv.empty? ? configuration.paths : @argv

  observations = collect_observations(configuration, options)
  candidates = SigGen::Generator.new(configuration: configuration, paths: paths,
                                     observations: observations,
                                     include_private: options.fetch(:include_private)).run
  mode = options.fetch(:mode).to_sym

  if mode == :write
    dispatch_write(candidates, configuration, options)
  else
    dispatch_print_or_diff(candidates, mode, options)
  end
  0
end