Skip to content

Commit

Permalink
Add support for --greedy* options in HOMEBREW_CASK_OPTS
Browse files Browse the repository at this point in the history
  • Loading branch information
jck112 committed Feb 23, 2024
1 parent d0a3f09 commit bb30264
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Library/Homebrew/cmd/upgrade.rb
Expand Up @@ -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).",
Expand Down
17 changes: 16 additions & 1 deletion Library/Homebrew/env_config.rb
Expand Up @@ -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`:" \
Expand Down Expand Up @@ -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|
Expand Down
36 changes: 36 additions & 0 deletions Library/Homebrew/test/env_config_spec.rb
Expand Up @@ -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

0 comments on commit bb30264

Please sign in to comment.