Class: LLMExperiment::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_experiment/cli.rb,
lib/llm_experiment/cli/new_command.rb,
lib/llm_experiment/cli/run_command.rb,
lib/llm_experiment/cli/build_command.rb,
lib/llm_experiment/cli/clean_command.rb,
lib/llm_experiment/cli/login_command.rb,
lib/llm_experiment/cli/parse_command.rb,
lib/llm_experiment/cli/shell_command.rb,
lib/llm_experiment/cli/doctor_command.rb,
lib/llm_experiment/cli/status_command.rb,
lib/llm_experiment/cli/metrics_command.rb,
lib/llm_experiment/cli/version_command.rb,
lib/llm_experiment/cli/sanitize_command.rb

Defined Under Namespace

Classes: BuildCommand, CleanCommand, Command, DoctorCommand, LoginCommand, MetricsCommand, NewCommand, ParseCommand, RunCommand, SanitizeCommand, ShellCommand, StatusCommand, VersionCommand

Constant Summary collapse

COMMANDS =

rubocop:disable Style/MutableConstant -- command files register themselves at load time

{}

Class Method Summary collapse

Class Method Details

.capture_help_to_stderrObject



53
54
55
# File 'lib/llm_experiment/cli.rb', line 53

def self.capture_help_to_stderr
  print_help($stderr)
end


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/llm_experiment/cli.rb', line 40

def self.print_help(io = $stdout)
  io.puts "llmx — run controlled, reproducible experiments on coding agents"
  io.puts
  io.puts "Usage: llmx COMMAND [options]"
  io.puts
  width = COMMANDS.keys.map(&:length).max
  COMMANDS.sort.each do |name, klass|
    io.puts format("  %-#{width}s  %s", name, klass.summary)
  end
  io.puts
  io.puts "Run `llmx COMMAND --help` for details."
end

.register(name, klass) ⇒ Object



9
10
11
# File 'lib/llm_experiment/cli.rb', line 9

def self.register(name, klass)
  COMMANDS[name] = klass
end

.run(argv) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/llm_experiment/cli.rb', line 13

def self.run(argv)
  argv = argv.dup
  name = argv.shift
  name = "version" if %w[-v --version].include?(name)

  if name.nil? || %w[-h --help help].include?(name)
    print_help
    return 0
  end

  klass = COMMANDS[name]
  unless klass
    warn "llmx: unknown command #{name.inspect}"
    warn ""
    capture_help_to_stderr
    return 1
  end

  klass.new.call(argv)
  0
rescue Error => e
  warn "llmx: #{e.message}"
  1
rescue Interrupt
  130
end