Skip to content

Commit

Permalink
Merge pull request #17940 from HaraldNordgren/cask_deps
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid committed Aug 5, 2024
2 parents a8e6262 + feb1d55 commit 87fec6c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Library/Homebrew/cask/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def self.get_info(cask)
output << "#{repo}\n" if repo
output << name_info(cask)
output << desc_info(cask)
deps = deps_info(cask)
output << deps if deps
language = language_info(cask)
output << language if language
output << "#{artifact_info(cask)}\n"
Expand Down Expand Up @@ -76,6 +78,22 @@ def self.desc_info(cask)
EOS
end

sig { params(cask: Cask).returns(T.nilable(String)) }
def self.deps_info(cask)
depends_on = cask.depends_on

formula_deps = Array(depends_on[:formula]).map(&:to_s)
cask_deps = Array(depends_on[:cask]).map { |dep| "#{dep} (cask)" }

all_deps = formula_deps + cask_deps
return if all_deps.empty?

<<~EOS
#{ohai_title("Dependencies")}
#{all_deps.join(", ")}
EOS
end

sig { params(cask: Cask).returns(T.nilable(String)) }
def self.language_info(cask)
return if cask.languages.empty?
Expand Down
38 changes: 38 additions & 0 deletions Library/Homebrew/test/cask/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,44 @@
EOS
end

it "prints cask dependencies if the Cask has any" do
expect do
described_class.info(Cask::CaskLoader.load("with-depends-on-cask-multiple"))
end.to output(<<~EOS).to_stdout
==> with-depends-on-cask-multiple: 1.2.3
https://brew.sh/with-depends-on-cask-multiple
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/w/with-depends-on-cask-multiple.rb
==> Name
None
==> Description
None
==> Dependencies
local-caffeine (cask), local-transmission (cask)
==> Artifacts
Caffeine.app (App)
EOS
end

it "prints cask and formulas dependencies if the Cask has both" do
expect do
described_class.info(Cask::CaskLoader.load("with-depends-on-everything"))
end.to output(<<~EOS).to_stdout
==> with-depends-on-everything: 1.2.3
https://brew.sh/with-depends-on-everything
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/w/with-depends-on-everything.rb
==> Name
None
==> Description
None
==> Dependencies
unar, local-caffeine (cask), with-depends-on-cask (cask)
==> Artifacts
Caffeine.app (App)
EOS
end

it "prints auto_updates if the Cask has `auto_updates true`" do
expect do
described_class.info(Cask::CaskLoader.load("with-auto-updates"))
Expand Down

0 comments on commit 87fec6c

Please sign in to comment.