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
98
# 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
  @atif_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



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
126
127
128
129
130
131
# File 'lib/miniswen/cli.rb', line 100

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)

  begin
    result = agent.run(instruction)
  rescue StandardError => e
    write_results(agent.partial_result(error_message(e)))
    raise
  end

  write_results(result)

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