<commit_before># encoding: utf-8

module Eye::Cli::Server
private

  def server_started?
    _cmd(:ping) == :pong
  end

  def loader_path
    filename = File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. .. bin loader_eye]))
    File.exists?(filename) ? filename : nil
  end

  def ruby_path
    require 'rbconfig'
    RbConfig::CONFIG['bindir'] + '/ruby'
  end

  def ensure_loader_path
    unless loader_path
      error! "start monitoring needs to run under ruby with installed gem 'eye'"
    end
  end

  def server_start_foreground(conf = nil)
    ensure_loader_path
    Eye::Local.ensure_eye_dir

    if server_started?
      _cmd(:quit) && sleep(1) # stop previous server
    end

    args = []
    args += ['--config', conf] if conf
    args += ['--logger', 'stdout']
    if Eye::Local.local_runner
      args += ['--stop_all']
      args += ['--dir', Eye::Local.dir]
      args += ['--config', Eye::Local.eyefile] unless conf
    end

    Process.exec(ruby_path, loader_path, *args)
  end

  def server_start(configs)
    ensure_loader_path<commit_msg>Check config for ruby binary<commit_after># encoding: utf-8

module Eye::Cli::Server
private

  def server_started?
    _cmd(:ping) == :pong
  end

  def loader_path
    filename = File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. .. bin loader_eye]))
    File.exists?(filename) ? filename : nil
  end

  def ruby_path
    require 'rbconfig'
    File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
  end

  def ensure_loader_path
    unless loader_path
      error! "start monitoring needs to run under ruby with installed gem 'eye'"
    end
  end

  def server_start_foreground(conf = nil)
    ensure_loader_path
    Eye::Local.ensure_eye_dir

    if server_started?
      _cmd(:quit) && sleep(1) # stop previous server
    end

    args = []
    args += ['--config', conf] if conf
    args += ['--logger', 'stdout']
    if Eye::Local.local_runner
      args += ['--stop_all']
      args += ['--dir', Eye::Local.dir]
      args += ['--config', Eye::Local.eyefile] unless conf
    end

    Process.exec(ruby_path, loader_path, *args)
  end

  def server_start(configs)
    ensure_loader_path
{'fraction_non_alphanumeric': 0.1302367941712204, 'fraction_numerical': 0.0018214936247723133, 'mean_word_length': 3.091247672253259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4401045', 'n_tokens_mistral': 747, 'n_tokens_neox': 706, 'n_words': 182}