Class: Lemans::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/lemans/cli.rb,
lib/lemans/cli/board_reporter.rb,
lib/lemans/cli/progress_reporter.rb

Overview

The commands. Thin on purpose: everything a command does is a call into a class somebody can drive without a terminal.

Defined Under Namespace

Classes: BoardReporter, ProgressReporter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
# File 'lib/lemans/cli.rb', line 12

def self.exit_on_failure? = true

Instance Method Details

#clobberObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/lemans/cli.rb', line 102

def clobber
  clobber = Clobber.new(
    runs_dir: options[:runs_dir],
    tasks: options[:task],
    ttl_sec: Units.seconds(options[:ttl], field: "--ttl"),
    invalid: options[:invalid]
  )
  doomed = clobber.matches
  return say "lemans: nothing to clobber under #{options[:runs_dir]}" if doomed.empty?

  unless options[:force]
    doomed.each { say _1.to_s }
    return say "lemans: nothing deleted" unless yes?("Delete #{doomed.size} run(s) under #{options[:runs_dir]}? [y/N]")
  end

  removed = clobber.call
  say "deleted #{removed.size} run(s)"
rescue ConfigError => e
  raise Thor::Error, "lemans: #{e.message}"
end

#reportObject



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/lemans/cli.rb', line 130

def report
  results = Results::Report.load(options[:runs_dir], tag: options[:tag])
  if results.empty?
    tagged = options[:tag] ? " tagged #{options[:tag].inspect}" : ""
    raise Thor::Error, "lemans: no results#{tagged} under #{options[:runs_dir]}"
  end

  results = Results::Aggregate.new(results, keys: Results::Aggregate.keys(options[:aggregate])) if options[:aggregate]
  results.order_by!(options[:sort]) if options[:sort]
  options[:format] == "csv" ? say(results.to_csv) : print_report(results)
rescue ConfigError => e
  raise Thor::Error, "lemans: #{e.message}"
end

#run_benchObject



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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/lemans/cli.rb', line 45

def run_bench
  # The bundled pricing registry ages faster than the gem: refresh once up
  # front, so every trial prices completions against the same revision.
  Miniswen.refresh_registry!

  bench = Bench.load(options[:bench])
  tasks = select_tasks(bench)

  run = Run.new(
    bench: bench,
    tasks: tasks,
    agent_name: options[:agent] || bench.agent.name,
    model: options[:model],
    backend: options[:backend],
    runs_dir: options[:runs_dir],
    attempts: Integer(options[:attempts]),
    concurrency: Integer(options[:concurrency]),
    resume: options[:resume]
  )
  if run.total.zero?
    say_status :resume, "nothing to run — every task × model already has " \
                        "#{options[:attempts]} scored attempt(s)", :green
  end

  # A tty gets the live board; a pipe gets plain streamed lines.
  progress =
    if interactive?
      models = options[:model] || (bench.agent.models.empty? ? [bench.agent.model] : bench.agent.models)
      BoardReporter.new(tasks: tasks.map(&:name), models: models,
                        attempts: Integer(options[:attempts]), total: run.total)
    else
      ProgressReporter.new(shell: shell, task_width: tasks.map { _1.name.length }.max)
    end
  progress.start
  summary = run.call { |event, data| progress.record(event, data) }
  progress.stop

  say ""
  say_status :report, "collecting results from #{options[:runs_dir]}", :cyan
  print_report Results::Report.load(options[:runs_dir])
  exit 130 if summary[:interrupted]
  exit 1 if summary[:invalid].positive?
rescue ConfigError => e
  raise Thor::Error, "lemans: #{e.message}"
rescue Interrupt
  say ""
  exit 130
ensure
  progress&.stop
end

#tasksObject



23
24
25
26
27
28
29
30
31
# File 'lib/lemans/cli.rb', line 23

def tasks
  bench = Bench.load(options[:bench])
  print_table(
    [%w[task difficulty tags description]] +
    select_tasks(bench).map { [_1.name, _1.difficulty, _1.tags.join(","), _1.description] }
  )
rescue ConfigError => e
  raise Thor::Error, "lemans: #{e.message}"
end

#versionObject



16
17
18
# File 'lib/lemans/cli.rb', line 16

def version
  say VERSION
end