<commit_before>#:  * `tap-info`:
#:    Display a brief summary of all installed taps.
#:
#:  * `tap-info` (`--installed`|<taps>):
#:    Display detailed information about one or more <taps>.
#:
#:    Pass `--installed` to display information on all installed taps.
#:
#:  * `tap-info` `--json=`<version> (`--installed`|<taps>):
#:    Print a JSON representation of <taps>. Currently the only accepted value
#:    for <version> is `v1`.
#:
#:    Pass `--installed` to get information on installed taps.
#:
#:    See the docs for examples of using the JSON output:
#:    <https://docs.brew.sh/Querying-Brew.html>

require "tap"

module Homebrew
  module_function

  def tap_info
    # TODO: This still returns a non-alphabetised list on APFS.
    if ARGV.include? "--installed"
      taps = Tap
    else
      taps = ARGV.named.sort.map do |name|
        Tap.fetch(name)
      end
    end

    if ARGV.json == "v1"
      print_tap_json(taps)
    else
      print_tap_info(taps)
    end
  end

  def print_tap_info(taps)
    if taps.none?
      tap_count = 0
      formula_count = 0
      command_count = 0
      pinned_count = 0
      private_count = 0
      Tap.each do |tap|
        tap_count += 1
        formula_count += tap.formula_files.size
        command_count += tap.command_files.size
        pinned_count += 1 if tap.pinned?
        private_count += 1 if tap.private?
      end
      info = Formatter.pluralize(tap_count, "tap").to_s
      info += ", #{pinned_count} pinned"
      info += ", #{private_count} private"
      info += ", #{Formatter.pluralize(formula_count, "formula")}"
      info += ", #{Formatter.pluralize(command_count, "command")}"
      info += ", #{Tap::TAP_DIRECTORY.abv}" if Tap::TAP_DIRECTORY.directory?
      puts info<commit_msg>tap-info: sort taps by name to handle APFS<commit_after>#:  * `tap-info`:
#:    Display a brief summary of all installed taps.
#:
#:  * `tap-info` (`--installed`|<taps>):
#:    Display detailed information about one or more <taps>.
#:
#:    Pass `--installed` to display information on all installed taps.
#:
#:  * `tap-info` `--json=`<version> (`--installed`|<taps>):
#:    Print a JSON representation of <taps>. Currently the only accepted value
#:    for <version> is `v1`.
#:
#:    Pass `--installed` to get information on installed taps.
#:
#:    See the docs for examples of using the JSON output:
#:    <https://docs.brew.sh/Querying-Brew.html>

require "tap"

module Homebrew
  module_function

  def tap_info
    if ARGV.include? "--installed"
      taps = Tap
    else
      taps = ARGV.named.sort.map do |name|
        Tap.fetch(name)
      end
    end

    if ARGV.json == "v1"
      print_tap_json(taps.sort_by {|tap| tap.to_s})
    else
      print_tap_info(taps.sort_by {|tap| tap.to_s})
    end
  end

  def print_tap_info(taps)
    if taps.none?
      tap_count = 0
      formula_count = 0
      command_count = 0
      pinned_count = 0
      private_count = 0
      Tap.each do |tap|
        tap_count += 1
        formula_count += tap.formula_files.size
        command_count += tap.command_files.size
        pinned_count += 1 if tap.pinned?
        private_count += 1 if tap.private?
      end
      info = Formatter.pluralize(tap_count, "tap").to_s
      info += ", #{pinned_count} pinned"
      info += ", #{private_count} private"
      info += ", #{Formatter.pluralize(formula_count, "formula")}"
      info += ", #{Formatter.pluralize(command_count, "command")}"
      info += ", #{Tap::TAP_DIRECTORY.abv}" if Tap::TAP_DIRECTORY.directory?
      puts info
{'fraction_non_alphanumeric': 0.13588948407104595, 'fraction_numerical': 0.00563856780377784, 'mean_word_length': 2.6766839378238343, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '3287883', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1162, 'n_words': 313}