Class: Lemans::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/lemans/cli.rb,
lib/lemans/cli/report.rb,
lib/lemans/cli/board_reporter.rb,
lib/lemans/cli/report/aggregate.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, Report

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


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

def self.exit_on_failure? = true

Instance Method Details

#clobberObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/lemans/cli.rb', line 112

def clobber
  store = Stores::FS.new(options[:runs_dir])
  clobber = Clobber.new(store, tasks: options[:task], ttl: options[: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 it.id }
    return say "lemans: nothing deleted" unless yes?("Delete #{doomed.size} run(s) under #{options[:runs_dir]}? [y/N]")
  end

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

#init(dir = ".") ⇒ Object



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

def init(dir = ".")
  self.destination_root = dir
  directory "bench", "."
  say_status :done, "prove the bench with `lemans run --bench #{dir} --agent oracle`", :cyan
end

#reportObject



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/lemans/cli.rb', line 138

def report
  store = Stores::FS.new(options[:runs_dir])
  results = Report.load(store, tags: options[:tag], names: options[:task])
  raise Thor::Error, "lemans: no matching results found" if results.empty?

  results = Report::Aggregate.new(results, keys: Report::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



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
95
96
97
98
99
100
101
102
103
104
# File 'lib/lemans/cli.rb', line 58

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!

  config = Config.load_file(options[:bench])
  config.load_options(**options.transform_keys(&:to_sym))

  tasks = filter_tasks(config.tasks, tags: options[:tag], name: options[:task])

  store = Stores::FS.new(options[:runs_dir], filterer: SecretsFilter.default)

  runner = Runner.new(config, tasks, store:, resume: options[:resume])

  if runner.resuming? && runner.attempts.empty?
    say_status :resume, "nothing to run — every task × model already has " \
                        "#{config.attempts} scored attempt(s)", :green

    return
  end

  reporter =
    if interactive?
      BoardReporter.new(tasks: tasks.map(&:name), models: config.models,
                        attempts: config.attempts, total: runner.attempts.size)
    else
      ProgressReporter.new(shell:, tasks: tasks.map(&:name))
    end

  reporter.start

  summary = runner.run(reporter)

  say ""
  say_status :report, "collecting results from #{options[:runs_dir]}", :cyan
  print_report Report.load(store)

  exit 130 if summary.status == :interrupted
  exit 1 if summary.status == :invalid
rescue ConfigError => e
  raise Thor::Error, "lemans: #{e.message}"
rescue Interrupt
  say ""
  exit 130
ensure
  reporter&.stop
end

#tasksObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lemans/cli.rb', line 34

def tasks
  config = Config.load_file(options[:bench])
  tasks = filter_tasks(config.tasks, tags: options[:tag])

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

#versionObject



20
21
22
# File 'lib/lemans/cli.rb', line 20

def version
  say VERSION
end