Skip to content

Commit

Permalink
env_config: deprecate setting boolean vars to falsy values
Browse files Browse the repository at this point in the history
The way we handle boolean environment variables is a bit unfortunate.
For example, setting `HOMEBREW_EVAL_ALL=false` actually enables
`HOMEBREW_EVAL_ALL`.

Let's fix this by deprecating setting boolean environment variables to
common false-y values (`false`, `0`, `nil`, `no`, and `off`) so that we
can later ignore these false-y values when reading boolean environment
variables.
  • Loading branch information
carlocab committed Sep 25, 2024
1 parent 94416e8 commit d9a69cb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,18 @@ def env_method_name(env, hash)

if hash[:boolean]
define_method(method_name) do
ENV[env].present?
env_value = ENV.fetch(env, nil)

falsy_values = %w[false no off nil 0]
if falsy_values.include(env_value&.downcase)
odeprecated "#{env}=#{env_value}", <<~EOS
If you wish to enable #{env}, #{env}=1
If you wish to disable #{env}, #{env}=
EOS
end

# TODO: Uncomment the remaining part of the line below after the deprecation/disable cycle.
env_value.present? # && !falsy_values.include(env_value.downcase)
end
elsif hash[:default].present?
define_method(method_name) do
Expand Down

0 comments on commit d9a69cb

Please sign in to comment.