Class: Miniswen::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/miniswen/cli.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Reporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



88
89
90
91
92
93
94
95
96
97
# File 'lib/miniswen/cli.rb', line 88

def initialize
  @instruction = nil
  @model = ENV.fetch("MINISWEN_MODEL", nil)
  @options = {}
  @verbose = false
  @quiet = false
  @results_path = nil
  @refresh_registry = false
  @skip_registry_refresh = false
end

Instance Attribute Details

#instructionObject (readonly)

Returns the value of attribute instruction.



86
87
88
# File 'lib/miniswen/cli.rb', line 86

def instruction
  @instruction
end

#modelObject (readonly)

Returns the value of attribute model.



86
87
88
# File 'lib/miniswen/cli.rb', line 86

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



86
87
88
# File 'lib/miniswen/cli.rb', line 86

def options
  @options
end

Instance Method Details

#runObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/miniswen/cli.rb', line 99

def run
  parse_args!

  # Require the core library after parsing options,
  # so env flags kick in
  require "miniswen"

  refresh_registry_and_exit if @refresh_registry

  Miniswen.refresh_registry! unless @skip_registry_refresh

  require "miniswen/local"

  reporter = @quiet ? nil : Reporter.new(verbose: @verbose)
  agent = Agent.new(model:, reporter:, environment: Local.new, **options)

  result = agent.run(instruction)

  File.write(@results_path, JSON.generate(result.to_h)) if @results_path

  if result.success?
    reporter&.print_summary(result)
  else
    reporter&.print_failure(result)
    Kernel.exit(1)
  end
end