Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show dependencies for casks #17940

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = depends_on[:formula]&.map(&:to_s) || []
cask_deps = depends_on[:cask]&.map { |dep| "#{dep} (cask)" } || []
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved

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