Class: RailVerdict::CLI

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

Constant Summary collapse

EXIT_OK =
0
EXIT_POLICY_FAIL =
1
EXIT_NO_GATE =
2
EXIT_INTERRUPTED =
130
FORMATS =
%w[console json sarif].freeze
DEFAULT_CONFIG_PATH =
".railverdict.yml"
USAGE =
<<~USAGE
  Usage: railverdict <command> [options]

  Commands:
    init             Write the default .railverdict.yml configuration
    doctor           Report configuration and analyzer observations
    check            Run verification and print the gate result
    baseline create  Deferred boundary; Phase 3 owns baseline writes
    findings         Print normalized findings from the evidence run
    explain          Explain a finding with optional AI
    investigate      Investigate top findings with optional AI
    repair           Build a deterministic repair packet for a finding
    mcp              MCP adapter (serve)

  Global options:
    --help           Show this usage
    --version        Show the railverdict version
USAGE

Instance Method Summary collapse

Constructor Details

#initialize(stdout: $stdout, stderr: $stderr, working_directory: Dir.pwd) ⇒ CLI

Returns a new instance of CLI.



35
36
37
38
39
# File 'lib/rail_verdict/cli.rb', line 35

def initialize(stdout: $stdout, stderr: $stderr, working_directory: Dir.pwd)
  @stdout = stdout
  @stderr = stderr
  @working_directory = working_directory
end

Instance Method Details

#run(argv) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rail_verdict/cli.rb', line 41

def run(argv)
  command = argv.first
  case command
  when nil, "-h", "--help", "help"
    @stdout.puts USAGE
    EXIT_OK
  when "--version", "-V"
    @stdout.puts "railverdict #{RailVerdict::VERSION}"
    EXIT_OK
  when "init"
    command_init(argv.drop(1))
  when "doctor"
    command_doctor(argv.drop(1))
  when "check"
    command_check(argv.drop(1))
  when "baseline"
    command_baseline(argv.drop(1))
  when "findings"
    command_findings(argv.drop(1))
  when "explain"
    command_explain(argv.drop(1))
  when "investigate"
    command_investigate(argv.drop(1))
  when "repair"
    command_repair(argv.drop(1))
  when "mcp"
    command_mcp(argv.drop(1))
  else
    @stderr.puts "railverdict: unknown command: #{command}"
    @stderr.puts USAGE
    EXIT_NO_GATE
  end
rescue RailVerdict::UsageError => error
  @stderr.puts "railverdict: #{error.message}"
  @stderr.puts USAGE
  EXIT_NO_GATE
end