# typed: strict
# frozen_string_literal: true

require "utils/output"
require "bundle/extensions"

module Homebrew
  # Helper module for querying Homebrew-specific environment variables.
  #
  # @api internal
  module EnvConfig
    include Utils::Output::Mixin
    extend Utils::Output::Mixin

    module_function

    BUNDLE_CORE_TYPES = T.let({
      brew: "formula dependencies",
      cask: "cask dependencies",
      tap:  "tap dependencies",
    }.freeze, T::Hash[Symbol, String])

    BUNDLE_DISABLE_ENVS = T.let(
      {
        cleanup: [BUNDLE_CORE_TYPES, Homebrew::Bundle.extensions.select(&:cleanup_supported?).to_h do |extension|
          [extension.type, extension.banner_name]
        end],
        dump:    [BUNDLE_CORE_TYPES, Homebrew::Bundle.extensions.select(&:dump_disable_supported?).to_h do |extension|
          [extension.type, extension.banner_name]
        end],
      }.flat_map do |command, type_descriptions|
        type_descriptions.reduce(&:merge).map do |type, description|
          verb = (command == :cleanup) ? "clean up" : "dump"
          [
            :"HOMEBREW_BUNDLE_#{command.upcase}_NO_#{type.to_s.upcase}",
            {
              description: "If set, `brew bundle #{command}` will not #{verb} #{description}.",
              boolean:     true,
            },
          ]
        end
      end.sort.to_h.freeze,
      T::Hash[Symbol, T::Hash[Symbol, T.untyped]],
    )

    ENVS = T.let({
      HOMEBREW_ALLOWED_TAPS:                     {
        description: "A space-separated list of taps. Homebrew will refuse to install a " \
                     "formula unless it and all of its dependencies are in an official tap " \
                     "or in a tap on this list. Each entry is a `user/repository` name " \
                     "(which matches only taps using the default GitHub remote) or a remote " \
                     "URL (required to match taps with a custom remote).",
      },
      HOMEBREW_API_AUTO_UPDATE_SECS:             {
        description: "Check Homebrew's API for new formulae or cask data every " \
                     "`$HOMEBREW_API_AUTO_UPDATE_SECS` seconds. Alternatively, disable API auto-update " \
                     "checks entirely with `$HOMEBREW_NO_AUTO_UPDATE`.",
        default:     450,
      },
      HOMEBREW_API_DOMAIN:                       {
        description:  "Use this URL as the download mirror for Homebrew JSON API. " \
                      "If metadata files at that URL are temporarily unavailable, " \
                      "the default API domain will be used as a fallback mirror.",
        default_text: "`https://formulae.brew.sh/api`.",
        default:      HOMEBREW_API_DEFAULT_DOMAIN,
      },
      HOMEBREW_ARCH:                             {
        description: "Linux only: Pass this value to a type name representing the compiler's `-march` option.",
        default:     "native",
      },
      HOMEBREW_ARTIFACT_DOMAIN:                  {
        description: "Prefix all download URLs, including those for bottles, with this value. " \
                     "For example, `export HOMEBREW_ARTIFACT_DOMAIN=http://localhost:8080` will cause a " \
                     "formula with the URL `https://example.com/foo.tar.gz` to instead download from " \
                     "`http://localhost:8080/https://example.com/foo.tar.gz`. " \
                     "Bottle URLs however, have their domain replaced with this prefix. " \
                     "This results in e.g. " \
                     "`https://ghcr.io/v2/homebrew/core/gettext/manifests/0.21` " \
                     "to instead be downloaded from " \
                     "`http://localhost:8080/v2/homebrew/core/gettext/manifests/0.21`",
      },
      HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK:      {
        description: "When `$HOMEBREW_ARTIFACT_DOMAIN` and `$HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK` are both set, " \
                     "if the request to `$HOMEBREW_ARTIFACT_DOMAIN` fails then Homebrew will error rather than " \
                     "trying any other/default URLs.",
        boolean:     :set,
      },
      HOMEBREW_ASK:                              {
        description: "Ask mode is the default for `brew install`, `brew upgrade` and " \
                     "`brew reinstall` commands. Ask mode prints the plan before proceeding and prompts only " \
                     "if the plan includes dependencies, dependants or packages other than named arguments. " \
                     "Otherwise, it only prints the plan. The confirmation prompt is skipped without a TTY.",
        boolean:     :set,
        disabled_by: :HOMEBREW_NO_ASK,
        default:     true,
        replacement: "the default behaviour",
        odeprecated: true,
      },
      HOMEBREW_AUTO_UPDATE_QUIET:                {
        description: "If set, the auto-update run before commands like `brew install`, `brew upgrade` or " \
                     "`brew tap` will not show information about new, outdated or deleted formulae and casks.",
        boolean:     true,
      },
      HOMEBREW_AUTO_UPDATE_SECS:                 {
        description:  "Run `brew update` once every `$HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \
                      "e.g. `brew install`, `brew upgrade` or `brew tap`. Alternatively, " \
                      "disable auto-update entirely with `$HOMEBREW_NO_AUTO_UPDATE`.",
        default_text: "`86400` (24 hours), `3600` (1 hour) if a developer command has been run " \
                      "or `300` (5 minutes) if `$HOMEBREW_NO_INSTALL_FROM_API` is set.",
        # Keep in sync with the auto-update defaults in Library/Homebrew/brew.sh.
        default:      lambda {
          if ENV["HOMEBREW_NO_INSTALL_FROM_API"].present? || ENV["HOMEBREW_AUTO_UPDATE_TAP"].present?
            300
          elsif ENV["HOMEBREW_DEV_CMD_RUN"].present?
            3600
          else
            86400
          end
        },
      },
      HOMEBREW_AVOID_NESTED_SANDBOXING:          {
        description: "If set, skip Homebrew's sandbox when it is itself running inside another " \
                     "sandbox, for an unprivileged user outside the default prefix. This trades " \
                     "Homebrew's build-time network and filesystem denial for trust in the outer " \
                     "sandbox. Homebrew errors out if the prefix or group makes skipping " \
                     "unsupported.",
        boolean:     :set,
      },
      HOMEBREW_BAT:                              {
        description: "If set, use `bat` for the `brew cat` command.",
        boolean:     true,
      },
      HOMEBREW_BAT_CONFIG_PATH:                  {
        description:  "Use this as the `bat` configuration file.",
        default_text: "`$BAT_CONFIG_PATH`.",
      },
      HOMEBREW_BAT_THEME:                        {
        description:  "Use this as the `bat` theme for syntax highlighting.",
        default_text: "`$BAT_THEME`.",
      },
      HOMEBREW_BOTTLE_DOMAIN:                    {
        description:  "Use this URL as the download mirror for bottles and their manifests. " \
                      "If a bottle or manifest is unavailable at the mirror, " \
                      "the default bottle domain will be used as a fallback. " \
                      "Prefer `$HOMEBREW_ARTIFACT_DOMAIN` for a mirror that transparently proxies all " \
                      "Homebrew downloads. " \
                      "For example, `export HOMEBREW_BOTTLE_DOMAIN=http://localhost:8080` will cause all bottles " \
                      "to download from the prefix `http://localhost:8080/`.",
        default_text: "`https://ghcr.io/v2/homebrew/core`.",
        default:      HOMEBREW_BOTTLE_DEFAULT_DOMAIN,
      },
      HOMEBREW_BREW_GIT_REMOTE:                  {
        description: "Use this URL as the Homebrew/brew `git`(1) remote.",
        default:     HOMEBREW_BREW_DEFAULT_GIT_REMOTE,
      },
      HOMEBREW_BROWSER:                          {
        description:  "Use this as the browser when opening project homepages.",
        default_text: "`$BROWSER` or the OS's default browser.",
      },
      **BUNDLE_DISABLE_ENVS.select { |env,| env < :HOMEBREW_BUNDLE_DESCRIBE },
      HOMEBREW_BUNDLE_DESCRIBE:                  {
        description: "If set, add a description comment above each line in `brew bundle dump` and " \
                     "`brew bundle add`, unless the dependency does not have a description. This is the default " \
                     "unless `$HOMEBREW_BUNDLE_NO_DESCRIBE` is set.",
        boolean:     true,
        disabled_by: :HOMEBREW_BUNDLE_NO_DESCRIBE,
        default:     true,
        replacement: "the default behaviour",
        odeprecated: true,
      },
      HOMEBREW_BUNDLE_DUMP_DESCRIBE:             {
        description: "If set, add a description comment above each line in `brew bundle dump` " \
                     "unless the dependency does not have a description. Use `$HOMEBREW_BUNDLE_DESCRIBE` instead.",
        boolean:     true,
        replacement: :HOMEBREW_BUNDLE_DESCRIBE,
        odeprecated: true,
      },
      **BUNDLE_DISABLE_ENVS.select { |env,| env > :HOMEBREW_BUNDLE_DESCRIBE },
      HOMEBREW_BUNDLE_FORCE_INSTALL_CLEANUP:     {
        description: "If set, run `brew bundle cleanup --force` after `brew bundle install`.",
        boolean:     true,
      },
      HOMEBREW_BUNDLE_INSTALL_CLEANUP:           {
        description: "If set, run `brew bundle cleanup` after `brew bundle install`.",
        boolean:     true,
        hidden:      true,
      },
      HOMEBREW_BUNDLE_JOBS:                      {
        # `HOMEBREW_BUNDLE_JOBS=auto` is the default.
        description: "Use this value as the number of formula installations to run in parallel for " \
                     "`brew bundle install`. Use `auto` for the number of CPU cores (max 4).",
        default:     "auto",
      },
      HOMEBREW_BUNDLE_NO_DESCRIBE:               {
        description: "If set, do not enable bundle description comments from `$HOMEBREW_BUNDLE_DESCRIBE` or " \
                     "the default. This does not disable an explicit `--describe`.",
        boolean:     true,
      },
      HOMEBREW_BUNDLE_NO_JOBS:                   {
        description: "If set, do not enable parallel jobs from `$HOMEBREW_BUNDLE_JOBS` or its default. " \
                     "This does not disable an explicit `--jobs`.",
        boolean:     true,
      },
      HOMEBREW_BUNDLE_NO_SECRETS:                {
        description: "If set, `brew bundle exec`, `brew bundle env` and `brew bundle sh` will attempt to remove " \
                     "secrets from the environment. This is the default unless `$HOMEBREW_BUNDLE_SECRETS` is set.",
        boolean:     true,
        disabled_by: :HOMEBREW_BUNDLE_SECRETS,
        default:     true,
        replacement: "the default behaviour",
        odeprecated: true,
      },
      HOMEBREW_BUNDLE_SECRETS:                   {
        description: "If set, do not enable the default secret scrubbing. " \
                     "This does not disable an explicit `--no-secrets`.",
        boolean:     true,
      },
      HOMEBREW_BUNDLE_USER_CACHE:                {
        description: "If set, use this directory as the `bundle`(1) user cache.",
      },
      HOMEBREW_CACHE:                            {
        description:  "Use this directory as the download cache.",
        default_text: "macOS: `~/Library/Caches/Homebrew`, " \
                      "Linux: `$XDG_CACHE_HOME/Homebrew` or `~/.cache/Homebrew`.",
        default:      HOMEBREW_DEFAULT_CACHE,
      },
      HOMEBREW_CASK_OPTS:                        {
        description: "Append these options to all `cask` commands. All `--*dir` options, " \
                     "`--language`, `--require-sha` and `--no-binaries` are supported. " \
                     "For example, you might add something like the following to your " \
                     "`~/.profile`, `~/.bash_profile`, or `~/.zshenv`:" \
                     "\n\n    `export HOMEBREW_CASK_OPTS=\"--appdir=${HOME}/Applications --fontdir=/Library/Fonts\"`",
      },
      HOMEBREW_CASK_OPTS_BINARIES:               {
        description: "Enable linking of helper executables for casks. Use " \
                     "`$HOMEBREW_CASK_OPTS` instead.",
        replacement: "HOMEBREW_CASK_OPTS",
        odeprecated: true,
      },
      HOMEBREW_CASK_OPTS_REQUIRE_SHA:            {
        description: "Require all casks to have a checksum. Use `$HOMEBREW_CASK_OPTS` instead.",
        replacement: "HOMEBREW_CASK_OPTS",
        odeprecated: true,
      },
      HOMEBREW_CLEANUP_MAX_AGE_DAYS:             {
        description: "Cleanup all cached files older than this many days.",
        default:     120,
      },
      HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS:       {
        description: "If set, `brew install`, `brew upgrade` and `brew reinstall` will cleanup all formulae " \
                     "when this number of days has passed.",
        default:     30,
      },
      HOMEBREW_COLOR:                            {
        description: "If set, force colour output on non-TTY outputs.",
        boolean:     :set,
        disabled_by: :HOMEBREW_NO_COLOR,
      },
      HOMEBREW_CORE_GIT_REMOTE:                  {
        description:  "Use this URL as the Homebrew/homebrew-core `git`(1) remote.",
        default_text: "`https://github.com/Homebrew/homebrew-core`.",
        default:      HOMEBREW_CORE_DEFAULT_GIT_REMOTE,
      },
      HOMEBREW_CURLRC:                           {
        description: "If set to an absolute path (i.e. beginning with `/`), pass it with `--config` when invoking " \
                     "`curl`(1). " \
                     "If set but _not_ a valid path, do not pass `--disable`, which disables the " \
                     "use of `.curlrc`.",
      },
      HOMEBREW_CURL_PATH:                        {
        description: "Linux only: Set this value to a new enough `curl` executable for Homebrew to use.",
        default:     "curl",
      },
      HOMEBREW_CURL_RETRIES:                     {
        description: "Pass the given retry count to `--retry` when invoking `curl`(1).",
        default:     3,
      },
      HOMEBREW_CURL_VERBOSE:                     {
        description: "If set, pass `--verbose` when invoking `curl`(1).",
        boolean:     true,
      },
      HOMEBREW_DEBUG:                            {
        description: "If set, always assume `--debug` when running commands.",
        boolean:     :set,
      },
      HOMEBREW_DEVELOPER:                        {
        description: "If set, tweak behaviour to be more relevant for Homebrew developers (active or " \
                     "budding) by e.g. turning warnings into errors.",
        boolean:     :set,
      },
      HOMEBREW_DISABLE_DEBREW:                   {
        description: "If set, the interactive formula debugger available via `--debug` will be disabled.",
        boolean:     true,
      },
      HOMEBREW_DISABLE_LOAD_FORMULA:             {
        description: "If set, refuse to load formulae. This is useful when formulae are not trusted (such " \
                     "as in pull requests).",
        boolean:     true,
      },
      HOMEBREW_DISPLAY:                          {
        description:  "Use this X11 display when opening a page in a browser, for example with " \
                      "`brew home`. Primarily useful on Linux.",
        default_text: "`$DISPLAY`.",
      },
      HOMEBREW_DISPLAY_INSTALL_TIMES:            {
        description: "If set, print install times for each formula at the end of the run.",
        boolean:     true,
      },
      HOMEBREW_DOCKER_REGISTRY_BASIC_AUTH_TOKEN: {
        description: "Use this base64 encoded username and password for authenticating with a Docker registry " \
                     "proxying GitHub Packages. If set to `none`, no authentication header will be sent. " \
                     "This can be used, if remote `$HOMEBREW_ARTIFACT_DOMAIN` does not support any authentication. " \
                     "If `$HOMEBREW_DOCKER_REGISTRY_TOKEN` is set, it will be used instead.",
      },
      HOMEBREW_DOCKER_REGISTRY_TOKEN:            {
        description: "Use this bearer token for authenticating with a Docker registry proxying GitHub Packages. " \
                     "Preferred over `$HOMEBREW_DOCKER_REGISTRY_BASIC_AUTH_TOKEN`.",
      },
      HOMEBREW_DOWNLOAD_CONCURRENCY:             {
        description: "Homebrew will download in parallel using this many concurrent connections. " \
                     "The default, `auto`, will use twice the number of available CPU cores " \
                     "(what our benchmarks showed to produce the best performance). " \
                     "If set to `1`, Homebrew will download in serial.",
        default:     "auto",
      },
      HOMEBREW_EDITOR:                           {
        description:  "Use this editor when editing a single formula, or several formulae in the " \
                      "same directory." \
                      "\n\n    *Note:* `brew edit` will open all of Homebrew as discontinuous files " \
                      "and directories. Visual Studio Code can handle this correctly in project mode, but many " \
                      "editors will do strange things in this case.",
        default_text: "`$EDITOR` or `$VISUAL`.",
      },
      HOMEBREW_ENV_SYNC_STRICT:                  {
        description: "If set, `brew *env-sync` will only sync the exact installed versions of formulae.",
        boolean:     true,
      },
      HOMEBREW_EVAL_ALL:                         {
        description: "If set, `brew` commands evaluate all trusted formulae and casks, " \
                     "executing their arbitrary code. Use `$HOMEBREW_REQUIRE_TAP_TRUST` or " \
                     "`$HOMEBREW_NO_REQUIRE_TAP_TRUST` instead.",
        boolean:     true,
        replacement: "HOMEBREW_REQUIRE_TAP_TRUST or HOMEBREW_NO_REQUIRE_TAP_TRUST",
        odeprecated: true,
      },
      HOMEBREW_FAIL_LOG_LINES:                   {
        description: "Output this many lines of output on formula `system` failures.",
        default:     15,
      },
      HOMEBREW_FORBIDDEN_CASKS:                  {
        description: "A space-separated list of casks. Homebrew will refuse to install a " \
                     "cask if it or any of its dependencies is on this list.",
      },
      HOMEBREW_FORBIDDEN_CASK_ARTIFACTS:         {
        description: "A space-separated list of cask artifact types (e.g. `pkg installer`) that should be " \
                     "forbidden during cask installation. " \
                     "Valid values: `pkg`, `installer`, `binary`, `uninstall`, `zap`, `app`, `suite`, " \
                     "`artifact`, `prefpane`, `qlplugin`, `dictionary`, `font`, `service`, `colorpicker`, " \
                     "`inputmethod`, `internetplugin`, `audiounitplugin`, `vstplugin`, `vst3plugin`, " \
                     "`screensaver`, `keyboardlayout`, `mdimporter`, `preflight`, `postflight`, " \
                     "`manpage`, `bashcompletion`, `fishcompletion`, `zshcompletion`, `stageonly`.",
      },
      HOMEBREW_FORBIDDEN_FORMULAE:               {
        description: "A space-separated list of formulae. Homebrew will refuse to install a " \
                     "formula or cask if it or any of its dependencies is on this list.",
      },
      HOMEBREW_FORBIDDEN_LICENSES:               {
        description: "A space-separated list of SPDX licence identifiers. Homebrew will refuse to install a " \
                     "formula if it or any of its dependencies has a licence on this list.",
      },
      HOMEBREW_FORBIDDEN_OWNER:                  {
        description: "The person who has set any `$HOMEBREW_FORBIDDEN_*` variables.",
        default:     "you",
      },
      HOMEBREW_FORBIDDEN_OWNER_CONTACT:          {
        description: "How to contact the `$HOMEBREW_FORBIDDEN_OWNER`, if set and necessary.",
      },
      HOMEBREW_FORBIDDEN_TAPS:                   {
        description: "A space-separated list of taps. Homebrew will refuse to install a " \
                     "formula if it or any of its dependencies is in a tap on this list. " \
                     "Each entry is a `user/repository` name (which matches only taps using " \
                     "the default GitHub remote) or a remote URL (required to match taps " \
                     "with a custom remote).",
      },
      HOMEBREW_FORBID_CASKS:                     {
        description: "If set, Homebrew will refuse to install any casks.",
        boolean:     true,
      },
      HOMEBREW_FORBID_PACKAGES_FROM_PATHS:       {
        description:  "If set, Homebrew will refuse to read formulae or casks provided from file paths, " \
                      "e.g. `brew install ./package.rb`.",
        boolean:      :set,
        default_text: "true unless `$HOMEBREW_DEVELOPER` is set.",
        # Keep in sync with forbid_packages_from_paths? below.
        default:      -> { ENV["HOMEBREW_TESTS"].blank? && ENV["HOMEBREW_DEVELOPER"].blank? },
      },
      HOMEBREW_FORCE_API_AUTO_UPDATE:            {
        description: "If set, update the Homebrew API formula or cask data even if " \
                     "`$HOMEBREW_NO_AUTO_UPDATE` is set.",
        boolean:     true,
      },
      HOMEBREW_FORCE_BREWED_CA_CERTIFICATES:     {
        description: "If set, always use a Homebrew-installed `ca-certificates` rather than the system version. " \
                     "Automatically set if the system version is too old.",
        boolean:     :set,
      },
      HOMEBREW_FORCE_BREWED_CURL:                {
        description: "If set, always use a Homebrew-installed `curl`(1) rather than the system version. " \
                     "Automatically set if the system version of `curl` is too old.",
        boolean:     :set,
      },
      HOMEBREW_FORCE_BREWED_GIT:                 {
        description: "If set, always use a Homebrew-installed `git`(1) rather than the system version. " \
                     "Automatically set if the system version of `git` is too old.",
        boolean:     :set,
      },
      HOMEBREW_FORCE_BREW_WRAPPER:               {
        description: "If set, require `brew` to be invoked by the value of " \
                     "`$HOMEBREW_FORCE_BREW_WRAPPER` for non-trivial `brew` commands.",
      },
      HOMEBREW_FORCE_BREW_WRAPPER_HELP_MESSAGE:  {
        description: "If set, appended to the `$HOMEBREW_FORCE_BREW_WRAPPER` error message to provide " \
                     "additional help or context to the user.",
      },
      HOMEBREW_FORCE_VENDOR_RUBY:                {
        description: "If set, always use Homebrew's vendored, relocatable Ruby version even if the system version " \
                     "of Ruby is new enough.",
        boolean:     :set,
      },
      HOMEBREW_FORMULA_BUILD_NETWORK:            {
        description: "If set, controls network access to the sandbox for formulae builds. Overrides any " \
                     "controls set through DSL usage inside formulae. Must be `allow` or `deny`. If no value is " \
                     "set through this environment variable or DSL usage, the default behaviour is `allow`.",
      },
      HOMEBREW_FORMULA_POSTINSTALL_NETWORK:      {
        description: "If set, controls network access to the sandbox for formulae postinstall. Overrides any " \
                     "controls set through DSL usage inside formulae. Must be `allow` or `deny`. If no value is " \
                     "set through this environment variable or DSL usage, the default behaviour is `allow`.",
      },
      HOMEBREW_FORMULA_TEST_NETWORK:             {
        description: "If set, controls network access to the sandbox for formulae test. Overrides any " \
                     "controls set through DSL usage inside formulae. Must be `allow` or `deny`. If no value is " \
                     "set through this environment variable or DSL usage, the default behaviour is `allow`.",
      },
      HOMEBREW_GITHUB_API_TOKEN:                 {
        description: "Use this personal access token for the GitHub API, for features such as " \
                     "`brew search`. You can create one at <https://github.com/settings/tokens>. If set, " \
                     "GitHub will allow you a greater number of API requests. For more information, see: " \
                     "<https://docs.github.com/en/rest/overview/rate-limits-for-the-rest-api>" \
                     "\n\n    *Note:* Homebrew doesn't require permissions for any of the scopes, but some " \
                     "developer commands may require additional permissions.",
      },
      HOMEBREW_GITHUB_PACKAGES_TOKEN:            {
        description: "Use this GitHub personal access token when accessing the GitHub Packages Registry " \
                     "(where bottles may be stored).",
      },
      HOMEBREW_GITHUB_PACKAGES_USER:             {
        description: "Use this username when accessing the GitHub Packages Registry (where bottles may be stored).",
      },
      HOMEBREW_GIT_COMMITTER_EMAIL:              {
        description: "Set the Git committer email to this value.",
      },
      HOMEBREW_GIT_COMMITTER_NAME:               {
        description: "Set the Git committer name to this value.",
      },
      HOMEBREW_GIT_EMAIL:                        {
        description: "Set the Git author name and, if `$HOMEBREW_GIT_COMMITTER_EMAIL` is unset, committer email to " \
                     "this value.",
      },
      HOMEBREW_GIT_NAME:                         {
        description: "Set the Git author name and, if `$HOMEBREW_GIT_COMMITTER_NAME` is unset, committer name to " \
                     "this value.",
      },
      HOMEBREW_GIT_PATH:                         {
        description: "Linux only: Set this value to a new enough `git` executable for Homebrew to use.",
        default:     "git",
      },
      HOMEBREW_INSTALL_BADGE:                    {
        description:  "Print this text before the installation summary of each successful build.",
        default_text: 'The "Beer Mug" emoji.',
        default:      "🍺",
      },
      HOMEBREW_LIVECHECK_AUTOBUMP:               {
        description: "If set, `brew livecheck` will include data for packages that are autobumped by BrewTestBot.",
        boolean:     true,
      },
      HOMEBREW_LIVECHECK_WATCHLIST:              {
        description:  "Consult this file for the list of formulae to check by default when no formula argument " \
                      "is passed to `brew livecheck`.",
        default_text: "`${XDG_CONFIG_HOME}/homebrew/livecheck_watchlist.txt` if `$XDG_CONFIG_HOME` is set " \
                      "or `~/.homebrew/livecheck_watchlist.txt` otherwise.",
        default:      "#{ENV.fetch("HOMEBREW_USER_CONFIG_HOME")}/livecheck_watchlist.txt",
      },
      HOMEBREW_LOCK_CONTEXT:                     {
        description: "If set, Homebrew will add this output as additional context for locking errors. " \
                     "This is useful when running `brew` in the background.",
      },
      HOMEBREW_LOGS:                             {
        description:  "Use this directory to store log files.",
        default_text: "macOS: `~/Library/Logs/Homebrew`, " \
                      "Linux: `${XDG_CACHE_HOME}/Homebrew/Logs` or `~/.cache/Homebrew/Logs`.",
        default:      HOMEBREW_DEFAULT_LOGS,
      },
      HOMEBREW_MAKE_JOBS:                        {
        description:  "Use this value as the number of parallel jobs to run when building with `make`(1).",
        default_text: "The number of available CPU cores.",
        default:      lambda {
          require "os"
          require "hardware"
          Hardware::CPU.cores
        },
      },
      HOMEBREW_NO_ANALYTICS:                     {
        description: "If set, do not send analytics. Google Analytics were destroyed. " \
                     "For more information, see: <https://docs.brew.sh/Analytics>",
        boolean:     :set,
      },
      HOMEBREW_NO_ASK:                           {
        description: "If set, do not enable default ask mode. This does not disable an explicit `--ask`.",
        boolean:     :set,
      },
      HOMEBREW_NO_AUTOREMOVE:                    {
        description: "If set, calls to `brew cleanup` and `brew uninstall` will not automatically " \
                     "remove unused formula dependents.",
        boolean:     true,
      },
      HOMEBREW_NO_AUTO_UPDATE:                   {
        description: "If set, do not automatically update before running some commands, e.g. " \
                     "`brew install`, `brew upgrade` or `brew tap`. Preferably, " \
                     "run this less often by setting `$HOMEBREW_AUTO_UPDATE_SECS` to a value higher than the " \
                     "default. Note that setting this and e.g. tapping new taps may result in a broken  " \
                     "configuration. Please ensure you always run `brew update` before reporting any issues.",
        boolean:     :set,
      },
      HOMEBREW_NO_BOOTSNAP:                      {
        description: "If set, do not use Bootsnap to speed up repeated `brew` calls.",
        boolean:     :set,
      },
      HOMEBREW_NO_CLEANUP_FORMULAE:              {
        description: "A comma-separated list of formulae. Homebrew will refuse to clean up " \
                     "or autoremove a formula if it appears on this list.",
      },
      HOMEBREW_NO_COLOR:                         {
        description:  "If set, do not print text with colour added.",
        default_text: "`$NO_COLOR`.",
        boolean:      :set,
      },
      HOMEBREW_NO_EMOJI:                         {
        description: "If set, do not print `$HOMEBREW_INSTALL_BADGE` on a successful build.",
        boolean:     :set,
      },
      HOMEBREW_NO_ENV_HINTS:                     {
        description: "If set, do not print any hints about changing Homebrew's behaviour with environment variables.",
        boolean:     :set,
      },
      HOMEBREW_NO_EVAL_ENV_SCRUBBING:            {
        # odeprecated: remove in a later release
        description: "If set, sensitive environment variables are available while evaluating " \
                     "formulae and casks. `$HOMEBREW_GITHUB_API_TOKEN` is still available during evaluation " \
                     "when this is unset. This setting will be removed in a later release.",
        boolean:     true,
        odeprecated: true,
      },
      HOMEBREW_NO_FORCE_BREW_WRAPPER:            {
        description: "`Deprecated:` If set, disables `$HOMEBREW_FORCE_BREW_WRAPPER` behaviour, even if set.",
        boolean:     :set,
      },
      HOMEBREW_NO_GITHUB_API:                    {
        description: "If set, do not use the GitHub API, e.g. for searches or fetching relevant issues " \
                     "after a failed install.",
        boolean:     true,
      },
      HOMEBREW_NO_INSECURE_REDIRECT:             {
        description: "If set, forbid redirects from secure HTTPS to insecure HTTP." \
                     "\n\n    *Note:* while ensuring your downloads are fully secure, this is likely to cause " \
                     "sources for certain formulae hosted by SourceForge, GNU or GNOME to fail to download.",
        boolean:     true,
      },
      HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK:    {
        description: "If set, do not check for broken linkage of dependents or outdated dependents after " \
                     "installing, upgrading or reinstalling formulae. This will result in fewer dependents " \
                     "(and their dependencies) being upgraded or reinstalled but may result in more breakage " \
                     "from running `brew install` <formula> or `brew upgrade` <formula>.",
        boolean:     true,
      },
      HOMEBREW_NO_INSTALL_CLEANUP:               {
        description: "If set, `brew install`, `brew upgrade` and `brew reinstall` will never automatically " \
                     "cleanup installed/upgraded/reinstalled formulae or all formulae every " \
                     "`$HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS` days. Alternatively, `$HOMEBREW_NO_CLEANUP_FORMULAE` " \
                     "allows specifying specific formulae to not clean up.",
        boolean:     :set,
      },
      HOMEBREW_NO_INSTALL_FROM_API:              {
        description: "If set, do not install formulae and casks in homebrew/core and homebrew/cask taps using " \
                     "Homebrew's API and instead use (large, slow) local checkouts of these repositories.",
        boolean:     :set,
      },
      HOMEBREW_NO_INSTALL_UPGRADE:               {
        description: "If set, `brew install` <formula|cask> will not upgrade <formula|cask> if it is installed but " \
                     "outdated.",
        boolean:     true,
      },
      HOMEBREW_NO_PATH_SHADOW_CHECK:             {
        description: "If set, `brew info` and `brew install` will not warn when a formula's executables are " \
                     "shadowed by other commands earlier on `$PATH`.",
        boolean:     true,
      },
      HOMEBREW_NO_REQUIRE_TAP_TRUST:             {
        # odeprecated: remove in a later release after tap trust checks are the default.
        description: "If set, do not require non-official tap formulae, casks or commands to be trusted. " \
                     "This is not recommended and will be removed in a later release. Also enables commands " \
                     "that evaluate all formulae and casks.",
        boolean:     :set,
      },
      HOMEBREW_NO_SANDBOX_CASK:                  {
        # odeprecated: make cask executable sandboxing mandatory in a future release.
        description: "If set, disable sandboxing for cask artifacts that generate files by running " \
                     "executables.",
        boolean:     true,
        odeprecated: true,
      },
      HOMEBREW_NO_SANDBOX_LINUX:                 {
        description: "If set, disable the Linux sandbox.",
        boolean:     :set,
      },
      HOMEBREW_NO_UPDATE_REPORT_NEW:             {
        description: "If set, `brew update` will not show the list of newly added formulae/casks.",
        boolean:     true,
      },
      HOMEBREW_NO_UPGRADE_AUTO_UPDATES_CASKS:    {
        description: "If set, `brew upgrade` will not automatically upgrade casks with `auto_updates true`. " \
                     "Does not affect `--greedy` or `--greedy-auto-updates` upgrades.",
        boolean:     :set,
      },
      HOMEBREW_NO_UPGRADE_QUIT_CASKS:            {
        description: "If set, `brew upgrade` will not quit running applications for casks during upgrades.",
        boolean:     true,
      },
      HOMEBREW_NO_VERIFY_ATTESTATIONS:           {
        description: "If set, Homebrew will not verify cryptographic attestations of build provenance for bottles " \
                     "from homebrew-core.",
        boolean:     :set,
      },
      HOMEBREW_PIP_INDEX_URL:                    {
        description:  "If set, `brew install` <formula> will use this URL to download PyPI package resources.",
        default_text: "`https://pypi.org/simple`.",
        default:      "https://pypi.org/simple",
      },
      HOMEBREW_PRY:                              {
        description: "This variable no longer has any effect because Pry is largely unmaintained upstream.",
        boolean:     true,
        odeprecated: true,
        replacement: "the default IRB backend (Pry is largely unmaintained upstream)",
      },
      HOMEBREW_REQUIRE_TAP_TRUST:                {
        # odeprecated: make tap trust checks default in a later release.
        description: "If set, require non-official tap formulae, casks and commands to be trusted with " \
                     "`brew trust` before Homebrew loads them. This is the default unless " \
                     "`$HOMEBREW_NO_REQUIRE_TAP_TRUST` is set. Also enables commands that evaluate all formulae " \
                     "and casks.",
        boolean:     :set,
        disabled_by: :HOMEBREW_NO_REQUIRE_TAP_TRUST,
        default:     true,
      },
      HOMEBREW_SANDBOX_LINUX:                    {
        description: "The Landlock sandbox is the default for formula installation and testing " \
                     "on Linux unless `$HOMEBREW_NO_SANDBOX_LINUX` is set.",
        boolean:     :set,
        disabled_by: :HOMEBREW_NO_SANDBOX_LINUX,
        default:     true,
        odeprecated: true,
      },
      HOMEBREW_SBOM:                             {
        description: "Write SBOM files for source installs.",
        boolean:     :set,
        default:     true,
        hidden:      true,
      },
      HOMEBREW_SIMULATE_MACOS_ON_LINUX:          {
        description: "If set, running Homebrew on Linux will simulate certain macOS code paths. This is useful " \
                     "when auditing macOS formulae while on Linux.",
        boolean:     true,
      },
      HOMEBREW_SKIP_OR_LATER_BOTTLES:            {
        description: "If set along with `$HOMEBREW_DEVELOPER`, do not use bottles from older versions " \
                     "of macOS. This is useful in development on new macOS versions.",
        boolean:     true,
      },
      HOMEBREW_SORBET_RECURSIVE:                 {
        description: "If set along with `$HOMEBREW_SORBET_RUNTIME`, enable recursive typechecking using Sorbet. " \
                     "Automatically enabled when running `brew tests`.",
        boolean:     true,
      },
      HOMEBREW_SORBET_RUNTIME:                   {
        description: "If set, enable runtime typechecking using Sorbet. " \
                     "Set by default when running `brew test`, `brew test-bot` or `brew tests`.",
        boolean:     :set,
      },
      HOMEBREW_SSH_CONFIG_PATH:                  {
        description:  "If set, Homebrew will use the given config file instead of `~/.ssh/config` when " \
                      "fetching Git repositories over SSH.",
        default_text: "`~/.ssh/config`",
        default:      -> { "#{Dir.home}/.ssh/config" },
      },
      HOMEBREW_SUDO_THROUGH_SUDO_USER:           {
        description: "If set, Homebrew will use the `$SUDO_USER` environment variable to define the user to " \
                     "`sudo`(8) through when running `sudo`(8).",
        boolean:     true,
      },
      HOMEBREW_SVN:                              {
        description:  "Use this as the `svn`(1) binary.",
        default_text: "A Homebrew-built Subversion (if installed), or the system-provided binary.",
      },
      HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY:        {
        description: "If set in Homebrew's system-wide environment file (`/etc/homebrew/brew.env`), " \
                     "the system-wide environment file will be loaded last to override any prefix or user settings.",
        boolean:     :set,
      },
      HOMEBREW_TEMP:                             {
        description:  "Use this path as the temporary directory for building packages. Changing " \
                      "this may be needed if your system temporary directory and Homebrew prefix are on " \
                      "different volumes, as macOS has trouble moving symlinks across volumes when the target " \
                      "does not yet exist. This issue typically occurs when using FileVault or custom SSD " \
                      "configurations.",
        default_text: "macOS: `/private/tmp`, Linux: `/var/tmp`.",
        default:      HOMEBREW_DEFAULT_TEMP,
      },
      HOMEBREW_UPDATE_TO_TAG:                    {
        description: "If set, always use the latest stable tag (even if developer commands " \
                     "have been run).",
        boolean:     :set,
      },
      HOMEBREW_UPGRADE_AUTO_UPDATES_CASKS:       {
        description: "If set, `brew upgrade` will automatically upgrade casks with `auto_updates true` when " \
                     "Homebrew detects that the version in the app bundle is older than the version in the tap. " \
                     "Does not affect `--greedy` or `--greedy-auto-updates` upgrades. This is the default unless " \
                     "`$HOMEBREW_NO_UPGRADE_AUTO_UPDATES_CASKS` is set.",
        boolean:     :set,
        disabled_by: :HOMEBREW_NO_UPGRADE_AUTO_UPDATES_CASKS,
        default:     true,
        replacement: "the default behaviour",
        odeprecated: true,
      },
      HOMEBREW_UPGRADE_GREEDY:                   {
        description: "If set, pass `--greedy` to all cask upgrade commands.",
        boolean:     true,
      },
      HOMEBREW_UPGRADE_GREEDY_CASKS:             {
        description: "A space-separated list of casks. Homebrew will act as " \
                     "if `--greedy` was passed when upgrading any cask on this list.",
      },
      HOMEBREW_USE_INTERNAL_API:                 {
        description: "If set, fetch formula and cask data from Homebrew's internal API. This is now the default.",
        boolean:     :set,
        replacement: "the default behaviour",
        odeprecated: true,
      },
      HOMEBREW_VERBOSE:                          {
        description: "If set, always assume `--verbose` when running commands.",
        boolean:     :set,
      },
      HOMEBREW_VERBOSE_USING_DOTS:               {
        description: "If set, verbose output will print a `.` no more than once a minute. This can be " \
                     "useful to avoid long-running Homebrew commands being killed due to no output.",
        boolean:     true,
      },
      HOMEBREW_VERIFY_ATTESTATIONS:              {
        description: "If set, Homebrew will use the `gh` tool to verify cryptographic attestations " \
                     "of build provenance for bottles from homebrew-core.",
        boolean:     :set,
        disabled_by: :HOMEBREW_NO_VERIFY_ATTESTATIONS,
      },
      SUDO_ASKPASS:                              {
        description: "If set, pass the `-A` option when calling `sudo`(8).",
      },
      all_proxy:                                 {
        description: "Use this SOCKS5 proxy for `curl`(1), `git`(1) and `svn`(1) when downloading through Homebrew.",
      },
      ftp_proxy:                                 {
        description: "Use this FTP proxy for `curl`(1), `git`(1) and `svn`(1) when downloading through Homebrew.",
      },
      http_proxy:                                {
        description: "Use this HTTP proxy for `curl`(1), `git`(1) and `svn`(1) when downloading through Homebrew.",
      },
      https_proxy:                               {
        description: "Use this HTTPS proxy for `curl`(1), `git`(1) and `svn`(1) when downloading through Homebrew.",
      },
      no_proxy:                                  {
        description: "A comma-separated list of hostnames and domain names excluded " \
                     "from proxying by `curl`(1), `git`(1) and `svn`(1) when downloading through Homebrew.",
      },
    }.freeze, T::Hash[Symbol, T::Hash[Symbol, T.untyped]])

    ANALYTICS_VARIABLES = T.let((ENVS.keys - [:HOMEBREW_NO_ANALYTICS]).freeze, T::Array[Symbol])

    sig { params(env: Symbol, hash: T::Hash[Symbol, T.untyped]).returns(String) }
    def env_method_name(env, hash)
      method_name = env.to_s
                       .sub(/^HOMEBREW_/, "")
                       .downcase
      method_name = "#{method_name}?" if hash[:boolean]
      method_name
    end

    sig { params(hash: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
    def hidden?(hash)
      !!(hash[:hidden] || hash[:odeprecated] || hash[:odisabled])
    end

    # The default value as human text, e.g. for the manpage or analytics:
    # `default_text` summarises defaults that vary by platform or machine.
    sig { params(env: Symbol).returns(T.nilable(String)) }
    def default_description(env)
      hash = ENVS[env]
      return if hash.nil?

      default_text = hash[:default_text]
      return default_text if default_text

      default = hash[:default]
      "`#{default}`." if default
    end

    # Defaults and parsing that cannot be expressed by the generated helpers.
    CUSTOM_IMPLEMENTATIONS = T.let(Set.new([
      :HOMEBREW_BUNDLE_JOBS,
      :HOMEBREW_CASK_OPTS,
      :HOMEBREW_DOWNLOAD_CONCURRENCY,
      :HOMEBREW_FORBID_PACKAGES_FROM_PATHS,
      :HOMEBREW_MAKE_JOBS,
    ]).freeze, T::Set[Symbol])

    # This tracks process-local warnings, so it must remain mutable.
    WARNED_DEPRECATED_ENVS = T.let(Set.new, T::Set[String]) # rubocop:disable Style/MutableConstant

    # Boolean env vars have two generated parsing modes. Use `boolean: true`
    # for Ruby-only toggles that accept explicit false values like `0` or
    # `false`. Use `boolean: :set` for toggles used by Bash or with inverse
    # `_NO_` variants, where any non-empty value must mean enabled. Use
    # `disabled_by:` when one boolean env var should override another.
    FALSY_VALUES = %w[false no off nil 0].freeze

    sig { params(env: Symbol).returns(T::Boolean) }
    def non_default_variable?(env)
      value = ENV.fetch(env.to_s, nil)
      # Blank values behave like unset in the generated accessors.
      return false if value.blank?

      config = ENVS.fetch(env)
      default = config.fetch(:default, config[:boolean] ? false : nil)
      default = default.call if default.respond_to?(:call)
      if config[:boolean]
        enabled = config[:boolean] == :set || FALSY_VALUES.exclude?(value.downcase)
        enabled != default
      else
        value != default.to_s
      end
    end

    # Whether the user set this variable rather than Homebrew exporting
    # it itself, e.g. `HOMEBREW_EDITOR` from `EDITOR`. The matching Bash
    # records `HOMEBREW_USER_SET_VARS` in `bin/brew` before any exports.
    sig { params(env: Symbol).returns(T::Boolean) }
    def user_set_variable?(env)
      return false if ENV.fetch(env.to_s, nil).blank?
      return true unless env.to_s.start_with?("HOMEBREW_")

      ENV.fetch("HOMEBREW_USER_SET_VARS", "").split.include?(env.to_s)
    end

    sig { returns(T::Array[String]) }
    def non_default_variables
      ENV.filter_map do |env, _value|
        env_symbol = env.to_sym
        env if ENVS.key?(env_symbol) && user_set_variable?(env_symbol) && non_default_variable?(env_symbol)
      end.sort
    end

    ENVS.each do |env, hash|
      # Needs a custom implementation.
      next if CUSTOM_IMPLEMENTATIONS.include?(env)

      method_name = env_method_name(env, hash)
      env = env.to_s

      if hash[:boolean]
        define_method(method_name) do
          return false if hash[:disabled_by] &&
                          Homebrew::EnvConfig.public_send(
                            env_method_name(hash[:disabled_by], ENVS.fetch(hash[:disabled_by])),
                          )

          env_value = env_value(env, hash)
          return true if hash[:default] == true && env_value.blank?

          env_value.present? && (hash[:boolean] == :set || FALSY_VALUES.exclude?(env_value.downcase))
        end
      elsif hash[:default].present?
        define_method(method_name) do
          value = env_value(env, hash).presence
          next value if value

          default = hash.fetch(:default)
          default = default.call if default.respond_to?(:call)
          default.to_s
        end
      else
        define_method(method_name) do
          env_value(env, hash).presence
        end
      end
    end

    sig { params(env: T.any(String, Symbol), hash: T::Hash[Symbol, T.untyped]).returns(T.nilable(String)) }
    def env_value(env, hash)
      env = env.to_s
      env_value = ENV.fetch(env, nil)
      return if env_value.nil?

      if env_value.present? && (hash[:default] != true || FALSY_VALUES.exclude?(env_value.downcase))
        odeprecated_env(env, hash)
      end
      if (replacement = hash[:replacement]).is_a?(Symbol)
        ENV[replacement.to_s] ||= env_value
      end
      env_value
    end

    sig { params(env: String, hash: T::Hash[Symbol, T.untyped]).void }
    def odeprecated_env(env, hash)
      return if !hash[:odeprecated] && !hash[:odisabled]
      return unless env_deprecation_applies?(hash)

      replacement = hash[:replacement] if hash.key?(:replacement)
      return if !Homebrew.raise_deprecation_exceptions? && ENV["HOMEBREW_TESTS"].blank? &&
                !WARNED_DEPRECATED_ENVS.add?(env)

      odeprecated env, replacement, disable: hash.fetch(:odisabled, false)
    end

    sig { params(hash: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
    def env_deprecation_applies?(hash)
      commands = Array(hash[:commands]).map(&:to_s)
      command = ENV.fetch("HOMEBREW_COMMAND", nil)
      return false if commands.present? && command.present? && commands.exclude?(command)

      subcommands = Array(hash[:subcommands]).map(&:to_s)
      subcommand = ENV.fetch("HOMEBREW_SUBCOMMAND", nil)
      return false if subcommands.present? && subcommand.present? && subcommands.exclude?(subcommand)

      true
    end

    sig { returns(T::Boolean) }
    def bottle_domain_custom?
      Homebrew::EnvConfig.bottle_domain != HOMEBREW_BOTTLE_DEFAULT_DOMAIN
    end

    sig { returns(String) }
    def make_jobs
      jobs = ENV["HOMEBREW_MAKE_JOBS"].to_i
      return jobs.to_s if jobs.positive?

      ENVS.fetch(:HOMEBREW_MAKE_JOBS)
          .fetch(:default)
          .call
          .to_s
    end

    sig { returns(T::Array[String]) }
    def cask_opts
      Shellwords.shellsplit(ENV.fetch("HOMEBREW_CASK_OPTS", ""))
    end

    sig { returns(T::Boolean) }
    def self.cask_opts_binaries?
      cask_opts.reverse_each do |opt|
        return true if opt == "--binaries"
        return false if opt == "--no-binaries"
      end

      method_name = :cask_opts_binaries
      env_value = T.cast(Homebrew::EnvConfig.public_send(method_name), T.nilable(String))
      return FALSY_VALUES.exclude?(env_value.downcase) if env_value.present?

      true
    end

    sig { returns(T::Boolean) }
    def cask_opts_require_sha?
      return true if cask_opts.include?("--require-sha")

      method_name = :cask_opts_require_sha
      env_value = T.cast(Homebrew::EnvConfig.public_send(method_name), T.nilable(String))
      env_value.present? && FALSY_VALUES.exclude?(env_value.downcase)
    end

    sig { returns(T.nilable(String)) }
    def bundle_jobs
      if (env_value = ENV.fetch("HOMEBREW_BUNDLE_NO_JOBS", nil)).present? && FALSY_VALUES.exclude?(env_value.downcase)
        return
      end

      default = ENVS.fetch(:HOMEBREW_BUNDLE_JOBS).fetch(:default).to_s
      jobs = ENV["HOMEBREW_BUNDLE_JOBS"].presence
      opoo "HOMEBREW_BUNDLE_JOBS=#{default} is now the default and no longer needs to be set." if jobs == default

      jobs || default
    end

    sig { returns(T::Boolean) }
    def forbid_packages_from_paths?
      # Undocumented opt-out for internal use.
      return false if ENV["HOMEBREW_INTERNAL_ALLOW_PACKAGES_FROM_PATHS"].present?

      return true if ENV["HOMEBREW_FORBID_PACKAGES_FROM_PATHS"].present?

      # Provide an opt-out for tests and developers.
      # Our testing framework installs formulae from file paths all over the place.
      # Keep in sync with the HOMEBREW_FORBID_PACKAGES_FROM_PATHS default above.
      ENV["HOMEBREW_TESTS"].blank? && ENV["HOMEBREW_DEVELOPER"].blank?
    end

    sig { returns(T::Boolean) }
    def automatically_set_no_install_from_api?
      ENV["HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API"].present?
    end

    sig { returns(T::Boolean) }
    def devcmdrun?
      Homebrew::Settings.read("devcmdrun") == "true"
    end

    sig { returns(Integer) }
    def download_concurrency
      concurrency = ENV.fetch("HOMEBREW_DOWNLOAD_CONCURRENCY", "auto")
      concurrency = if concurrency == "auto"
        require "os"
        require "hardware"
        Hardware::CPU.cores * 2
      else
        concurrency.to_i
      end

      [concurrency, 1].max
    end

    sig { returns(T::Boolean) }
    def tap_trust_configured?
      Homebrew::EnvConfig.require_tap_trust? || Homebrew::EnvConfig.no_require_tap_trust?
    end
  end
end
