Class: Lemans::CLI
- Inherits:
-
Thor
- Object
- Thor
- Lemans::CLI
- 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
12 |
# File 'lib/lemans/cli.rb', line 12 def self.exit_on_failure? = true |
Instance Method Details
#clobber ⇒ Object
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: [:runs_dir], tasks: [:task], ttl_sec: Units.seconds([:ttl], field: "--ttl"), invalid: [:invalid] ) doomed = clobber.matches return say "lemans: nothing to clobber under #{[:runs_dir]}" if doomed.empty? unless [:force] doomed.each { say _1.to_s } return say "lemans: nothing deleted" unless yes?("Delete #{doomed.size} run(s) under #{[:runs_dir]}? [y/N]") end removed = clobber.call say "deleted #{removed.size} run(s)" rescue ConfigError => e raise Thor::Error, "lemans: #{e.}" end |
#report ⇒ Object
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([:runs_dir], tag: [:tag]) if results.empty? tagged = [:tag] ? " tagged #{[:tag].inspect}" : "" raise Thor::Error, "lemans: no results#{tagged} under #{[:runs_dir]}" end results = Results::Aggregate.new(results, keys: Results::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
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([:bench]) tasks = select_tasks(bench) run = Run.new( bench: bench, tasks: tasks, agent_name: [:agent] || bench.agent.name, model: [:model], backend: [:backend], runs_dir: [:runs_dir], attempts: Integer([:attempts]), concurrency: Integer([:concurrency]), resume: [:resume] ) if run.total.zero? say_status :resume, "nothing to run — every task × model already has " \ "#{[:attempts]} scored attempt(s)", :green end # A tty gets the live board; a pipe gets plain streamed lines. progress = if interactive? models = [:model] || (bench.agent.models.empty? ? [bench.agent.model] : bench.agent.models) BoardReporter.new(tasks: tasks.map(&:name), models: models, attempts: Integer([: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 #{[:runs_dir]}", :cyan print_report Results::Report.load([:runs_dir]) exit 130 if summary[:interrupted] exit 1 if summary[:invalid].positive? rescue ConfigError => e raise Thor::Error, "lemans: #{e.}" rescue Interrupt say "" exit 130 ensure progress&.stop end |
#tasks ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/lemans/cli.rb', line 23 def tasks bench = Bench.load([:bench]) print_table( [%w[task difficulty tags description]] + select_tasks(bench).map { [_1.name, _1.difficulty, _1..join(","), _1.description] } ) rescue ConfigError => e raise Thor::Error, "lemans: #{e.}" end |
#version ⇒ Object
16 17 18 |
# File 'lib/lemans/cli.rb', line 16 def version say VERSION end |