<commit_before>module HomebrewArgvExtension
  def formula_install_option_names
    %w[
      --debug
      --env=
      --ignore-dependencies
      --cc=
      --build-from-source
      --devel
      --HEAD
      --keep-tmp
      --interactive
      --git
      --sandbox
      --no-sandbox
      --build-bottle
      --force-bottle
      --verbose
      -i
      -v
      -d
      -g
      -s
    ].freeze
  end

  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 do |name|
      if name.include?("/") || File.exist?(name)
        Formulary.factory(name, spec)
      else
        Formulary.find_with_priority(name, spec)
      end
    end.uniq(&:name)
  end

  def resolved_formulae
    require "formula"
    @resolved_formulae ||= (downcased_unique_named - casks).map do |name|
      if name.include?("/") || File.exist?(name)
        f = Formulary.factory(name, spec)
        if f.any_version_installed?
          tab = Tab.for_formula(f)
          resolved_spec = spec(nil) || tab.spec
          f.active_spec = resolved_spec if f.send(resolved_spec)
          f.build = tab
          if f.head? && tab.tabfile
            k = Keg.new(tab.tabfile.parent)
            f.version.update_commit(k.version.version.commit) if k.version.head?
          end
        end
      else
        rack = Formulary.to_rack(name)
        alias_path = Formulary.factory(name).alias_path
        f = Formulary.from_rack(rack, spec(nil), alias_path: alias_path)
      end

      # If this formula was installed with an alias that has since changed,
      # then it was specified explicitly in ARGV. (Using the alias would
      # instead have found the new formula.)
      #
      # Because of this, the user is referring to this specific formula,
      # not any formula targetted by the same alias, so in this context
      # the formula shouldn't be considered outdated if the alias used to
      # install it has changed.
      f.follow_installed_alias = false

      f
    end.uniq(&:name)
  end

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

  def kegs
    require "keg"
    require "formula"
    @kegs ||= downcased_unique_named.collect do |name|
      raise UsageError if name.empty?

      rack = Formulary.to_rack(name.downcase)

      dirs = rack.directory? ? rack.subdirs : []

      raise NoSuchKegError, rack.basename if dirs.empty?

      linked_keg_ref = HOMEBREW_LINKED_KEGS/rack.basename
      opt_prefix = HOMEBREW_PREFIX/"opt/#{rack.basename}"

      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)
        else
          f = if name.include?("/") || File.exist?(name)
            Formulary.factory(name)
          else
            Formulary.from_rack(rack)
          end

          unless (prefix = f.installed_prefix).directory?
            raise MultipleVersionsInstalledError, rack.basename
          end

          Keg.new(prefix)
        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) || raise(UsageError)
  end

  def value(name)
    arg_prefix = "--#{name}="
    flag_with_value = find { |arg| arg.start_with?(arg_prefix) }
    flag_with_value.strip_prefix(arg_prefix) if flag_with_value
  end

  # Returns an array of values that were given as a comma-seperated list.
  # @see value
  def values(name)
    return unless val = value(name)
    val.split(",")
  end

  def force?
    flag? "--force"
  end<commit_msg>ARGV.include? should return boolean<commit_after>module HomebrewArgvExtension
  def formula_install_option_names
    %w[
      --debug
      --env=
      --ignore-dependencies
      --cc=
      --build-from-source
      --devel
      --HEAD
      --keep-tmp
      --interactive
      --git
      --sandbox
      --no-sandbox
      --build-bottle
      --force-bottle
      --verbose
      -i
      -v
      -d
      -g
      -s
    ].freeze
  end

  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 do |name|
      if name.include?("/") || File.exist?(name)
        Formulary.factory(name, spec)
      else
        Formulary.find_with_priority(name, spec)
      end
    end.uniq(&:name)
  end

  def resolved_formulae
    require "formula"
    @resolved_formulae ||= (downcased_unique_named - casks).map do |name|
      if name.include?("/") || File.exist?(name)
        f = Formulary.factory(name, spec)
        if f.any_version_installed?
          tab = Tab.for_formula(f)
          resolved_spec = spec(nil) || tab.spec
          f.active_spec = resolved_spec if f.send(resolved_spec)
          f.build = tab
          if f.head? && tab.tabfile
            k = Keg.new(tab.tabfile.parent)
            f.version.update_commit(k.version.version.commit) if k.version.head?
          end
        end
      else
        rack = Formulary.to_rack(name)
        alias_path = Formulary.factory(name).alias_path
        f = Formulary.from_rack(rack, spec(nil), alias_path: alias_path)
      end

      # If this formula was installed with an alias that has since changed,
      # then it was specified explicitly in ARGV. (Using the alias would
      # instead have found the new formula.)
      #
      # Because of this, the user is referring to this specific formula,
      # not any formula targetted by the same alias, so in this context
      # the formula shouldn't be considered outdated if the alias used to
      # install it has changed.
      f.follow_installed_alias = false

      f
    end.uniq(&:name)
  end

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

  def kegs
    require "keg"
    require "formula"
    @kegs ||= downcased_unique_named.collect do |name|
      raise UsageError if name.empty?

      rack = Formulary.to_rack(name.downcase)

      dirs = rack.directory? ? rack.subdirs : []

      raise NoSuchKegError, rack.basename if dirs.empty?

      linked_keg_ref = HOMEBREW_LINKED_KEGS/rack.basename
      opt_prefix = HOMEBREW_PREFIX/"opt/#{rack.basename}"

      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)
        else
          f = if name.include?("/") || File.exist?(name)
            Formulary.factory(name)
          else
            Formulary.from_rack(rack)
          end

          unless (prefix = f.installed_prefix).directory?
            raise MultipleVersionsInstalledError, rack.basename
          end

          Keg.new(prefix)
        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

  def include?(arg)
    !(@n = index(arg)).nil?
  end

  def next
    at(@n+1) || raise(UsageError)
  end

  def value(name)
    arg_prefix = "--#{name}="
    flag_with_value = find { |arg| arg.start_with?(arg_prefix) }
    flag_with_value.strip_prefix(arg_prefix) if flag_with_value
  end

  # Returns an array of values that were given as a comma-seperated list.
  # @see value
  def values(name)
    return unless val = value(name)
    val.split(",")
  end

  def force?
    flag? "--force"
  end
{'fraction_non_alphanumeric': 0.09902772776377386, 'fraction_numerical': 0.0004801344376425399, 'mean_word_length': 2.119430924747286, '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': '5192704', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2661, 'n_words': 673}