<commit_before>class UsageError <RuntimeError; end
class FormulaUnspecifiedError <UsageError; end
class KegUnspecifiedError <UsageError; end

class MultipleVersionsInstalledError <RuntimeError
  attr :name

  def initialize name
    @name = name
    super "#{name} has multiple installed versions"
  end
end

class NoSuchKegError <RuntimeError
  attr :name

  def initialize name
    @name = name
    super "No such keg: #{HOMEBREW_CELLAR}/#{name}"
  end
end

module HomebrewArgvExtension
  def named
    @named ||= reject{|arg| arg[0..0] == '-'}
  end

  def options_only
    select {|arg| arg[0..0] == '-'}
  end

  def formulae
    require 'formula'
    @formulae ||= downcased_unique_named.map{ |name| Formula.factory(Formula.resolve_alias(name)) }
    raise FormulaUnspecifiedError if @formulae.empty?
    @formulae
  end

  def kegs
    require 'keg'
    require 'formula'
    @kegs ||= downcased_unique_named.collect do |name|
      d = HOMEBREW_CELLAR + Formula.resolve_alias(name)
      dirs = d.children.select{ |pn| pn.directory? } rescue []
      raise NoSuchKegError.new(name) if not d.directory? or dirs.length == 0
      raise MultipleVersionsInstalledError.new(name) if dirs.length > 1
      Keg.new dirs.first
    end
    raise KegUnspecifiedError if @kegs.empty?
    @kegs
  end

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

  def force?
    flag? '--force'
  end
  def verbose?
    flag? '--verbose' or ENV['HOMEBREW_VERBOSE']
  end
  def debug?
    flag? '--debug' or ENV['HOMEBREW_DEBUG']
  end
  def quieter?
    flag? '--quieter'
  end
  def interactive?
    flag? '--interactive'
  end
  def build_head?
    flag? '--HEAD'
  end

  def flag? flag
    options_only.each do |arg|
      return true if arg == flag
      next if arg[1..1] == '-'
      return true if arg.include? flag[2..2]
    end
    return false
  end

  def usage; <<-EOS.undent
    Usage: brew [-v|--version] [--prefix [formula]] [--cache [formula]]
                [--cellar [formula]] [--config] [--env] [--repository]
                [-h|--help] COMMAND [formula] ...

    Principle Commands:
      install formula ... [--ignore-dependencies] [--HEAD]
      list [--unbrewed|--versions] [formula] ...<commit_msg>Correct the principle usage of principal principles ;)<commit_after>class UsageError <RuntimeError; end
class FormulaUnspecifiedError <UsageError; end
class KegUnspecifiedError <UsageError; end

class MultipleVersionsInstalledError <RuntimeError
  attr :name

  def initialize name
    @name = name
    super "#{name} has multiple installed versions"
  end
end

class NoSuchKegError <RuntimeError
  attr :name

  def initialize name
    @name = name
    super "No such keg: #{HOMEBREW_CELLAR}/#{name}"
  end
end

module HomebrewArgvExtension
  def named
    @named ||= reject{|arg| arg[0..0] == '-'}
  end

  def options_only
    select {|arg| arg[0..0] == '-'}
  end

  def formulae
    require 'formula'
    @formulae ||= downcased_unique_named.map{ |name| Formula.factory(Formula.resolve_alias(name)) }
    raise FormulaUnspecifiedError if @formulae.empty?
    @formulae
  end

  def kegs
    require 'keg'
    require 'formula'
    @kegs ||= downcased_unique_named.collect do |name|
      d = HOMEBREW_CELLAR + Formula.resolve_alias(name)
      dirs = d.children.select{ |pn| pn.directory? } rescue []
      raise NoSuchKegError.new(name) if not d.directory? or dirs.length == 0
      raise MultipleVersionsInstalledError.new(name) if dirs.length > 1
      Keg.new dirs.first
    end
    raise KegUnspecifiedError if @kegs.empty?
    @kegs
  end

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

  def force?
    flag? '--force'
  end
  def verbose?
    flag? '--verbose' or ENV['HOMEBREW_VERBOSE']
  end
  def debug?
    flag? '--debug' or ENV['HOMEBREW_DEBUG']
  end
  def quieter?
    flag? '--quieter'
  end
  def interactive?
    flag? '--interactive'
  end
  def build_head?
    flag? '--HEAD'
  end

  def flag? flag
    options_only.each do |arg|
      return true if arg == flag
      next if arg[1..1] == '-'
      return true if arg.include? flag[2..2]
    end
    return false
  end

  def usage; <<-EOS.undent
    Usage: brew [-v|--version] [--prefix [formula]] [--cache [formula]]
                [--cellar [formula]] [--config] [--env] [--repository]
                [-h|--help] COMMAND [formula] ...

    Principal Commands:
      install formula ... [--ignore-dependencies] [--HEAD]
      list [--unbrewed|--versions] [formula] ...
{'fraction_non_alphanumeric': 0.12150141028422651, 'fraction_numerical': 0.00477326968973747, 'mean_word_length': 2.760195758564437, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, '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': '101278', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1540, 'n_words': 439}