Class: Lemans::CLI
- Inherits:
-
Thor
- Object
- Thor
- Lemans::CLI
- 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
- #clobber ⇒ Object
- #init(dir = ".") ⇒ Object
- #report ⇒ Object
- #run_bench ⇒ Object
- #tasks ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
16 |
# File 'lib/lemans/cli.rb', line 16 def self.exit_on_failure? = true |
Instance Method Details
#clobber ⇒ Object
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([:runs_dir]) clobber = Clobber.new(store, tasks: [:task], ttl: [:ttl], invalid: [:invalid]) doomed = clobber.matches return say "lemans: nothing to clobber under #{[:runs_dir]}" if doomed.empty? unless [:force] doomed.each { say it.id } return say "lemans: nothing deleted" unless yes?("Delete #{doomed.size} run(s) under #{[:runs_dir]}? [y/N]") end removed = clobber.execute! say "deleted #{removed.size} run(s)" rescue ConfigError => e raise Thor::Error, "lemans: #{e.}" 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 |
#report ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/lemans/cli.rb', line 138 def report store = Stores::FS.new([:runs_dir]) results = Report.load(store, tags: [:tag], names: [:task]) raise Thor::Error, "lemans: no matching results found" if results.empty? results = Report::Aggregate.new(results, keys: Report::Aggregate.keys([:aggregate])) if [:aggregate] results.order_by!([:sort]) if [:sort] [:format] == "csv" ? say(results.to_csv) : print_report(results) rescue ConfigError => e raise Thor::Error, "lemans: #{e.}" end |
#run_bench ⇒ Object
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([:bench]) config.(**.transform_keys(&:to_sym)) tasks = filter_tasks(config.tasks, tags: [:tag], name: [:task]) store = Stores::FS.new([:runs_dir], filterer: SecretsFilter.default) runner = Runner.new(config, tasks, store:, resume: [: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 #{[: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.}" rescue Interrupt say "" exit 130 ensure reporter&.stop end |
#tasks ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lemans/cli.rb', line 34 def tasks config = Config.load_file([:bench]) tasks = filter_tasks(config.tasks, tags: [:tag]) print_table( [ %w[task difficulty tags description] ] + tasks.map { [ it.name, it.difficulty, it..join(","), it.description ] } ) rescue ConfigError => e raise Thor::Error, "lemans: #{e.}" end |
#version ⇒ Object
20 21 22 |
# File 'lib/lemans/cli.rb', line 20 def version say VERSION end |