diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index ed712f3070f24e..87aa8bf527f3f5 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -91,12 +91,15 @@ def upgrade_args }], [:switch, "-g", "--greedy", { description: "Also include casks with `auto_updates true` or `version :latest`.", + env: :cask_opts_greedy, }], [:switch, "--greedy-latest", { description: "Also include casks with `version :latest`.", + env: :cask_opts_greedy_latest, }], [:switch, "--greedy-auto-updates", { description: "Also include casks with `auto_updates true`.", + env: :cask_opts_greedy_auto_updates, }], [:switch, "--[no-]binaries", { description: "Disable/enable linking of helper executables (default: enabled).", diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index c5d04c4082bad3..8d13eef3846112 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -95,7 +95,7 @@ module EnvConfig default: HOMEBREW_DEFAULT_CACHE, }, HOMEBREW_CASK_OPTS: { - description: "Append these options to all `cask` commands. All `--*dir` options, " \ + description: "Append these options to all `cask` commands. All `--*dir` options, `--greedy*` options," \ "`--language`, `--require-sha`, `--no-quarantine` and `--no-binaries` are supported. " \ "For example, you might add something like the following to your " \ "`~/.profile`, `~/.bash_profile`, or `~/.zshenv`:" \ @@ -475,6 +475,21 @@ def cask_opts Shellwords.shellsplit(ENV.fetch("HOMEBREW_CASK_OPTS", "")) end + sig { returns(T::Boolean) } + def cask_opts_greedy? + cask_opts.include?("--greedy") + end + + sig { returns(T::Boolean) } + def cask_opts_greedy_latest? + cask_opts.include?("--greedy-latest") + end + + sig { returns(T::Boolean) } + def cask_opts_greedy_auto_updates? + cask_opts.include?("--greedy-auto-updates") + end + sig { returns(T::Boolean) } def cask_opts_binaries? cask_opts.reverse_each do |opt| diff --git a/Library/Homebrew/test/env_config_spec.rb b/Library/Homebrew/test/env_config_spec.rb index 02fdd05948c896..9fc8662b5b1d88 100644 --- a/Library/Homebrew/test/env_config_spec.rb +++ b/Library/Homebrew/test/env_config_spec.rb @@ -63,4 +63,40 @@ expect(env_config.make_jobs).to eql("16") end end + + describe ".cask_opts_greedy" do + it "returns true if `--greedy` set" do + ENV["HOMEBREW_CASK_OPTS"] = "--greedy" + expect(env_config.cask_opts_greedy?).to be(true) + end + + it "returns false by default" do + ENV["HOMEBREW_CASK_OPTS"] = "" + expect(env_config.cask_opts_greedy?).to be(false) + end + end + + describe ".cask_opts_greedy_latest" do + it "returns true if `--greedy-latest` set" do + ENV["HOMEBREW_CASK_OPTS"] = "--greedy-latest" + expect(env_config.cask_opts_greedy_latest?).to be(true) + end + + it "returns false by default" do + ENV["HOMEBREW_CASK_OPTS"] = "" + expect(env_config.cask_opts_greedy_latest?).to be(false) + end + end + + describe ".cask_opts_greedy_auto_updates" do + it "returns true if `--greedy-auto-updates` set" do + ENV["HOMEBREW_CASK_OPTS"] = "--greedy-auto-updates" + expect(env_config.cask_opts_greedy_auto_updates?).to be(true) + end + + it "returns false by default" do + ENV["HOMEBREW_CASK_OPTS"] = "" + expect(env_config.cask_opts_greedy_auto_updates?).to be(false) + end + end end