From 58f8832a7e46895dc28cdbb105037fb0f22af3b4 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 27 Sep 2023 12:28:24 +0100 Subject: [PATCH] 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`. --- Library/Homebrew/cli/parser.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 9f845dbb37..fd0a64e2be 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -185,7 +185,12 @@ module Homebrew def env?(env) 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 def description(text = nil)