<commit_before>module HomebrewArgvExtension
  def named
    @named ||= self - options_only
  end

  def options_only
    select { |arg| arg.start_with?("-") }
  end

  def flags_only
    select { |arg| arg.start_with?("--") }
  end

  def formulae
    require "formula"
    @formulae ||= (downcased_unique_named - casks).map { |name| Formulary.factory(name, spec) }
  end

  def resolved_formulae
    require "formula"
    @resolved_formulae ||= (downcased_unique_named - casks).map do |name|
      if name.include?("/")
        Formulary.factory(name, spec)
      else
        Formulary.from_rack(HOMEBREW_CELLAR/name, spec)
      end
    end
  end

  def casks
    @casks ||= downcased_unique_named.grep HOMEBREW_CASK_TAP_FORMULA_REGEX
  end

  def kegs
    require 'keg'
    require 'formula'
    @kegs ||= downcased_unique_named.collect do |name|
      canonical_name = Formulary.canonical_name(name)
      rack = HOMEBREW_CELLAR/canonical_name
      dirs = rack.directory? ? rack.subdirs : []

      raise NoSuchKegError.new(canonical_name) if dirs.empty?

      linked_keg_ref = HOMEBREW_LIBRARY.join("LinkedKegs", canonical_name)
      opt_prefix = HOMEBREW_PREFIX.join("opt", canonical_name)

      begin
        if opt_prefix.symlink? && opt_prefix.directory?
          Keg.new(opt_prefix.resolved_path)
        elsif linked_keg_ref.symlink? && linked_keg_ref.directory?
          Keg.new(linked_keg_ref.resolved_path)
        elsif dirs.length == 1
          Keg.new(dirs.first)
        elsif (prefix = Formulary.factory(canonical_name).prefix).directory?
          Keg.new(prefix)
        else
          raise MultipleVersionsInstalledError.new(canonical_name)
        end
      rescue FormulaUnavailableError
        raise <<-EOS.undent
          Multiple kegs installed to #{rack}
          However we don't know which one you refer to.
          Please delete (with rm -rf!) all but one and then try again.
        EOS
      end
    end
  end

  # self documenting perhaps?
  def include? arg
    @n=index arg
  end
  def next
    at @n+1 or raise UsageError
  end

  def value arg
    arg = find {|o| o =~ /--#{arg}=(.+)/}
    $1 if arg
  end

  def force?
    flag? '--force'<commit_msg>ARGV#kegs: try to load fomrula from rack<commit_after>module HomebrewArgvExtension
  def named
    @named ||= self - options_only
  end

  def options_only
    select { |arg| arg.start_with?("-") }
  end

  def flags_only
    select { |arg| arg.start_with?("--") }
  end

  def formulae
    require "formula"
    @formulae ||= (downcased_unique_named - casks).map { |name| Formulary.factory(name, spec) }
  end

  def resolved_formulae
    require "formula"
    @resolved_formulae ||= (downcased_unique_named - casks).map do |name|
      if name.include?("/")
        Formulary.factory(name, spec)
      else
        Formulary.from_rack(HOMEBREW_CELLAR/name, spec)
      end
    end
  end

  def casks
    @casks ||= downcased_unique_named.grep HOMEBREW_CASK_TAP_FORMULA_REGEX
  end

  def kegs
    require 'keg'
    require 'formula'
    @kegs ||= downcased_unique_named.collect do |name|
      canonical_name = Formulary.canonical_name(name)
      rack = HOMEBREW_CELLAR/canonical_name
      dirs = rack.directory? ? rack.subdirs : []

      raise NoSuchKegError.new(canonical_name) if dirs.empty?

      linked_keg_ref = HOMEBREW_LIBRARY.join("LinkedKegs", canonical_name)
      opt_prefix = HOMEBREW_PREFIX.join("opt", canonical_name)

      begin
        if opt_prefix.symlink? && opt_prefix.directory?
          Keg.new(opt_prefix.resolved_path)
        elsif linked_keg_ref.symlink? && linked_keg_ref.directory?
          Keg.new(linked_keg_ref.resolved_path)
        elsif dirs.length == 1
          Keg.new(dirs.first)
        elsif (prefix = (name.include?("/") ? Formulary.factory(name) : Formulary.from_rack(rack)).prefix).directory?
          Keg.new(prefix)
        else
          raise MultipleVersionsInstalledError.new(canonical_name)
        end
      rescue FormulaUnavailableError
        raise <<-EOS.undent
          Multiple kegs installed to #{rack}
          However we don't know which one you refer to.
          Please delete (with rm -rf!) all but one and then try again.
        EOS
      end
    end
  end

  # self documenting perhaps?
  def include? arg
    @n=index arg
  end
  def next
    at @n+1 or raise UsageError
  end

  def value arg
    arg = find {|o| o =~ /--#{arg}=(.+)/}
    $1 if arg
  end

  def force?
    flag? '--force'
{'fraction_non_alphanumeric': 0.09968708091193562, 'fraction_numerical': 0.0013410818059901655, 'mean_word_length': 2.6088709677419355, 'pattern_counts': {'":': 0, '<': 7, '<?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': '643755', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1505, 'n_words': 349}