class Tryouts::CLI

def handle_version_flag(options, output_manager)

def handle_version_flag(options, output_manager)
  return unless options[:version]
  output_manager.raw("Tryouts version #{Tryouts::VERSION}")
  exit 0
end

def initialize

def initialize
  @options = {
    framework: :direct,
    verbose: false,
    inspect: false,
  }
end

def parse_args(args)

def parse_args(args)
  Tryouts.trace "Parsing arguments: #{args.inspect}"
  options = {}
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: try [OPTIONS] FILE...\n\nModern Tryouts test runner with framework translation"
    opts.separator "\nFramework Options:"
    opts.on('--direct', 'Direct execution with TestBatch (default)') { options[:framework] = :direct }
    opts.on('--rspec', 'Use RSpec framework') { options[:framework]                        = :rspec }
    opts.on('--minitest', 'Use Minitest framework') { options[:framework]                  = :minitest }
    opts.separator "\nGeneration Options:"
    opts.on('--generate-rspec', 'Generate RSpec code only') do
      options[:framework]     = :rspec
      options[:generate_only] = true
    end
    opts.on('--generate-minitest', 'Generate Minitest code only') do
      options[:framework]     = :minitest
      options[:generate_only] = true
    end
    opts.on('--generate', 'Generate code only (use with --rspec/--minitest)') do
      options[:generate_only] = true
      options[:framework]   ||= :rspec
    end
    opts.separator "\nExecution Options:"
    opts.on('--shared-context', 'Override default context mode') { options[:shared_context]         = true }
    opts.on('--no-shared-context', 'Override default context mode') { options[:shared_context]      = false }
    opts.on('-v', '--verbose', 'Show detailed test output with line numbers') { options[:verbose]   = true }
    opts.on('-f', '--fails', 'Show only failing tests') { options[:fails_only]                      = true }
    opts.on('-q', '--quiet', 'Minimal output (dots and summary only)') { options[:quiet]            = true }
    opts.on('-c', '--compact', 'Compact single-line output') { options[:compact]                    = true }
    opts.on('-l', '--live', 'Live status display') { options[:live_status]                          = true }
    opts.separator "\nInspection Options:"
    opts.on('-i', '--inspect', 'Inspect file structure without running tests') { options[:inspect] = true }
    opts.separator "\nGeneral Options:"
    opts.on('-V', '--version', 'Show version') { options[:version] = true }
    opts.on('-D', '--debug', 'Enable debug mode') do
      options[:debug] = true
      Tryouts.debug   = true
    end
    opts.on('-h', '--help', 'Show this help') do
      puts opts
      exit 0
    end
    opts.separator HELP.freeze
  end
  files = parser.parse(args)
  Tryouts.trace "Parsed files: #{files.inspect}, options: #{options.inspect}"
  [files, options]
rescue OptionParser::InvalidOption => ex
  Tryouts.info Console.color(:red, "Invalid option error: #{ex.message}")
  warn "Error: #{ex.message}"
  warn "Try 'try --help' for more information."
  exit 1
end

def run(files, **options)

def run(files, **options)
  @options.merge!(options)
  output_manager = FormatterFactory.create_output_manager(@options)
  handle_version_flag(@options, output_manager)
  validate_files_exist(files, output_manager)
  runner = TestRunner.new(
    files: files,
    options: @options,
    output_manager: output_manager,
  )
  runner.run
end

def validate_files_exist(files, output_manager)

def validate_files_exist(files, output_manager)
  missing_files = files.reject { |file| File.exist?(file) }
  unless missing_files.empty?
    missing_files.each { |file| output_manager.error("File not found: #{file}") }
    exit 1
  end
end