Class: Raif::CLI::Evals

Inherits:
Base
  • Object
show all
Defined in:
lib/raif/cli/evals.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Raif::CLI::Base

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/raif/cli/evals.rb', line 9

def run
  # Set test environment by default for evals
  ENV["RAILS_ENV"] ||= "test"
  ENV["RAIF_RUNNING_EVALS"] = "true"

  OptionParser.new do |opts|
    opts.banner = "Usage: raif evals [options] [FILE_PATHS]"

    opts.on("-e", "--environment ENV", "Rails environment (default: test)") do |env|
      ENV["RAILS_ENV"] = env
    end

    opts.on("-h", "--help", "Show this help message") do
      puts opts
      exit
    end
  end.parse!(args)

  # Parse file paths with optional line numbers
  file_paths = args.map do |arg|
    if arg.include?(":")
      file_path, line_number = arg.split(":", 2)
      { file_path: file_path, line_number: line_number.to_i }
    else
      { file_path: arg, line_number: nil }
    end
  end if args.any?

  # Find and load Rails application
  load_rails_application

  require "raif/evals"

  run = Raif::Evals::Run.new(file_paths: file_paths)
  run.execute
end