<commit_before>require 'ostruct'

module Homebrew extend self

  def link
    raise KegUnspecifiedError if ARGV.named.empty?

    if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero?
      raise "Cowardly refusing to `sudo brew link'\n#{SUDO_BAD_ERRMSG}"
    end

    mode = OpenStruct.new

    mode.overwrite = true if ARGV.include? '--overwrite'
    mode.dry_run = true if ARGV.dry_run?

    ARGV.kegs.each do |keg|
      if keg.linked?
        opoo "Already linked: #{keg}"
        puts "To relink: brew unlink #{keg.fname} && brew link #{keg.fname}"
        next
      end

      if mode.dry_run and mode.overwrite
        print "Would remove:\n" do
          keg.link(mode)
        end

        next
      elsif mode.dry_run
        print "Would link:\n" do
          keg.link(mode)
        end

        next
      end

      keg.lock do
        print "Linking #{keg}... " do
          puts "#{keg.link(mode)} symlinks created"
        end
      end
    end
  end

  private

  # Allows us to ensure a puts happens before the block exits so that if say,
  # an exception is thrown, its output starts on a new line.
  def print str, &block
    Kernel.print str<commit_msg>Require --force to link keg-only.<commit_after>require 'ostruct'

module Homebrew extend self

  def link
    raise KegUnspecifiedError if ARGV.named.empty?

    if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero?
      raise "Cowardly refusing to `sudo brew link'\n#{SUDO_BAD_ERRMSG}"
    end

    mode = OpenStruct.new

    mode.overwrite = true if ARGV.include? '--overwrite'
    mode.dry_run = true if ARGV.dry_run?

    ARGV.kegs.each do |keg|
      if keg.linked?
        opoo "Already linked: #{keg}"
        puts "To relink: brew unlink #{keg.fname} && brew link #{keg.fname}"
        next
      end

      if mode.dry_run and mode.overwrite
        print "Would remove:\n" do
          keg.link(mode)
        end

        next
      elsif mode.dry_run
        print "Would link:\n" do
          keg.link(mode)
        end

        next
      end

      f = Formula.factory(keg.fname)
      if f.keg_only? and not ARGV.force?
        opoo "#{keg.fname} is keg-only and must be linked with --force"
        puts "Note that doing so can interfere with building software."
        next
      end

      keg.lock do
        print "Linking #{keg}... " do
          puts "#{keg.link(mode)} symlinks created"
        end
      end
    end
  end

  private

  # Allows us to ensure a puts happens before the block exits so that if say,
  # an exception is thrown, its output starts on a new line.
  def print str, &block
    Kernel.print str
{'fraction_non_alphanumeric': 0.08943396226415094, 'fraction_numerical': 0.0, 'mean_word_length': 2.0436280137772673, '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': '490467', 'n_tokens_mistral': 911, 'n_tokens_neox': 863, 'n_words': 280}