cli/parser: check env var directly if there's no EnvConfig method.

Before this change, external commands, whether official or not, cannot
use the `env:` DSL for `Homebrew::CLI::Parser` without adding their
environment variable to `Homebrew::EnvConfig`.

Instead, if the method is not defined, check the environment variable
directly. This allows `env:` to be used as expected and allows
simplifying some (new) code in e.g. `brew bundle`.
This commit is contained in:
Mike McQuaid 2023-09-27 12:28:24 +01:00
parent 67be775fd9
commit 58f8832a7e
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829

View File

@ -185,7 +185,12 @@ module Homebrew
def env?(env) def env?(env)
return if env.blank? return if env.blank?
Homebrew::EnvConfig.try(:"#{env}?") method_name = :"#{env}?"
if Homebrew::EnvConfig.respond_to?(method_name)
Homebrew::EnvConfig.public_send(method_name)
else
ENV.fetch("HOMEBREW_#{env.upcase}", nil)
end
end end
def description(text = nil) def description(text = nil)