Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 15 additions & 14 deletions Library/Homebrew/cask/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module Cask
class Info
extend ::Utils::Output::Mixin

sig { params(cask: Cask, verbose: T::Boolean).returns(String) }
def self.get_info(cask, verbose: false)
# TODO: Remove installed_casks by loading only related casks, including renamed and unavailable ones.
Comment thread
HaraldNordgren marked this conversation as resolved.
Resolved
sig { params(cask: Cask, verbose: T::Boolean, installed_casks: T.nilable(T::Array[Cask])).returns(String) }
def self.get_info(cask, verbose: false, installed_casks: nil)
require "cask/installer"

installed = cask.installed?
Expand All @@ -27,7 +28,7 @@ def self.get_info(cask, verbose: false)
auto_updates: cask.auto_updates == true,
installation_status: [installation_info(cask, installed:)],
source_url: repo_url(cask),
installed_versions: installed_section_rows(cask),
installed_versions: installed_section_rows(cask, installed_casks:),
verbose:,
)}\n"
deps = deps_info(cask, mark_uninstalled: installed)
Expand All @@ -53,9 +54,9 @@ def self.get_info(cask, verbose: false)
output
end

sig { params(cask: Cask, args: Homebrew::Cmd::Info::Args).void }
def self.info(cask, args:)
puts get_info(cask, verbose: args.verbose?)
sig { params(cask: Cask, args: Homebrew::Cmd::Info::Args, installed_casks: T.nilable(T::Array[Cask])).void }
def self.info(cask, args:, installed_casks: nil)
puts get_info(cask, verbose: args.verbose?, installed_casks:)

return unless cask.tap&.core_cask_tap?

Expand All @@ -71,10 +72,13 @@ def self.installation_info(cask, installed:)
::Utils::InfoDisplay.installation_status(Tab.for_cask(cask))
end

sig { params(cask: Cask).returns(T::Array[::Utils::InfoDisplay::InstalledVersion]) }
def self.installed_section_rows(cask)
sig {
params(cask: Cask, installed_casks: T.nilable(T::Array[Cask]))
.returns(T::Array[::Utils::InfoDisplay::InstalledVersion])
}
def self.installed_section_rows(cask, installed_casks: nil)
base_token = cask.token.split("@", 2).fetch(0)
related_casks = [*Caskroom.casks, cask].uniq(&:full_name).select do |other|
related_casks = [*(installed_casks || Caskroom.casks), cask].uniq(&:token).select do |other|
other.token == base_token || other.token.start_with?("#{base_token}@")
end
related_casks.sort_by(&:full_name).filter_map do |installed_cask|
Expand All @@ -89,11 +93,7 @@ def self.installed_section_rows(cask)
else
""
end
details = if path_exists
["Caskroom: #{versioned_staged_path}"]
else
["#{versioned_staged_path} (#{Formatter.error("does not exist")})"]
end
details = path_exists ? ["Caskroom: #{versioned_staged_path}"] : []
if (tab = Tab.for_cask(installed_cask)).tabfile&.exist?
details << tab.to_s
end
Expand All @@ -109,6 +109,7 @@ def self.installed_section_rows(cask)
size:,
linked: false,
details:,
warning: ("#{versioned_staged_path} (#{Formatter.error("does not exist")})" unless path_exists),
)
end
end
Expand Down
9 changes: 5 additions & 4 deletions Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class NameSize < T::Struct

sig { override.void }
def run
@installed_casks = T.let(nil, T.nilable(T::Array[Cask::Cask]))
if args.sizes?
if args.no_named?
print_sizes
Expand Down Expand Up @@ -126,9 +127,10 @@ def run
elsif (json = args.json)
print_json(json, args.no_named? && !args.installed?)
elsif args.installed?
@installed_casks = Cask::Caskroom.casks unless args.formula?
T.let([
*(args.cask? ? [] : Formula.installed.sort),
*(args.formula? ? [] : Cask::Caskroom.casks.sort_by(&:full_name)),
*(@installed_casks || []).sort_by(&:full_name),
Comment thread
HaraldNordgren marked this conversation as resolved.
Resolved
], T::Array[T.any(Formula, Cask::Cask)]).each_with_index do |formula_or_cask, i|
puts unless i.zero?

Expand Down Expand Up @@ -734,7 +736,8 @@ def dep_display_s(dep)
def info_cask(cask)
require "cask/info"

Cask::Info.info(cask, args:)
@installed_casks ||= Cask::Caskroom.casks
Cask::Info.info(cask, args:, installed_casks: @installed_casks)
end

sig { params(cask: Cask::Cask).void }
Expand Down Expand Up @@ -827,5 +830,3 @@ def print_sizes(formulae: [], casks: [])
end
end
end

require "extend/os/cmd/info"
5 changes: 0 additions & 5 deletions Library/Homebrew/extend/os/cmd/info.rb

This file was deleted.

19 changes: 0 additions & 19 deletions Library/Homebrew/extend/os/linux/cmd/info.rb

This file was deleted.

19 changes: 0 additions & 19 deletions Library/Homebrew/extend/os/mac/cmd/info.rb

This file was deleted.

116 changes: 108 additions & 8 deletions Library/Homebrew/test/cask/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,20 @@ def mock_cask_installed(cask_name)
cask = Cask::CaskLoader.load("local-transmission")
allow(DeprecateDisable).to receive(:message).with(cask) { +"deprecated!\nReplacement:\n example\n" }

expect { described_class.info(cask, args:) }
.to output(%r{https://transmissionbt.com/\nDeprecated!\nReplacement:\n example\nNot installed}).to_stdout
expect { described_class.info(cask, args:) }.to output(<<~EOS).to_stdout
==> local-transmission (Transmission): 2.61
BitTorrent client
https://transmissionbt.com/
Deprecated!
Replacement:
example
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/l/local-transmission.rb
==> Requirements
Required: macOS >= 11
==> Apps
Transmission.app
EOS
end

it "prints inline summary information for casks" do
Expand All @@ -134,9 +146,22 @@ def mock_cask_installed(cask_name)
outdated?: true,
version: Cask::DSL::Version.new("2.61"),
supports_linux?: false)
(Cask::Caskroom.path/"local-transmission/2.60").mkpath
allow(Cask::Caskroom).to receive(:casks).and_return([])
allow(Cask::Tab).to receive(:for_cask).with(cask).and_return(Cask::Tab.empty)

expect { described_class.info(cask, args:) }
.to output(/==> .*↑.*: 2\.60 → 2\.61/).to_stdout
expect { described_class.info(cask, args:) }.to output(<<~EOS).to_stdout
==> local-transmission #{Formatter.success("↑")} (Transmission): 2.60 → 2.61
BitTorrent client
https://transmissionbt.com/
Installed (as dependency)
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/l/local-transmission.rb
==> Installed Versions
local-transmission #{Formatter.success("↑")} 2.60 → 2.61 (0B)
#{requirements_section(installed("macOS >= 11"))}
==> Apps
Transmission.app
EOS
end

describe "installed sibling cask versions" do
Expand Down Expand Up @@ -191,9 +216,79 @@ def mock_cask_installed(cask_name)
it "shows the available version for an outdated sibling" do
allow(installed_cask).to receive_messages(outdated?: true, version: Cask::DSL::Version.new("4.0"))

expect { described_class.info(cask, args:) }
.to output(/example@dev.*3\.2\.0-RC3 → 4\.0/).to_stdout
.and not_to_output.to_stderr
expect { described_class.info(cask, args:) }.to output(<<~EOS).to_stdout
#{oh1_title uninstalled("example")}: 3.0
Not installed
==> Installed Versions
example@dev #{Formatter.success("↑")} 3.2.0-RC3 → 4.0 (844MB)
EOS
end

it "shows a missing sibling directory without --verbose" do
missing_path = Cask::Caskroom.path/"missing-example/3.2.0-RC3"
allow(installed_cask).to receive(:caskroom_path).and_return(missing_path.parent)

expect { described_class.info(cask, args:) }.to output(<<~EOS).to_stdout
#{oh1_title uninstalled("example")}: 3.0
Not installed
==> Installed Versions
#{installed("example@dev")} 3.2.0-RC3
#{missing_path} (#{Formatter.error("does not exist")})
EOS
end
end

it "lists an installed cask only once when another tap has the same token" do
cask = Cask::Cask.new("example", tap: Tap.fetch("other/tools")) { version "2.0" }
installed_cask = Cask::Cask.new("example", tap: Tap.fetch("original/tools")) { version "1.0" }
(Cask::Caskroom.path/"example/1.0").mkpath
allow(cask).to receive_messages(installed?: true, installed_version: "1.0", outdated?: false)
allow(installed_cask).to receive_messages(installed?: true, installed_version: "1.0", outdated?: false)
allow(Cask::Caskroom).to receive(:casks).and_return([installed_cask])
allow(Cask::Tab).to receive(:for_cask).and_return(Cask::Tab.empty)
allow(described_class).to receive(:repo_url).with(cask).and_return(nil)

expect { described_class.info(cask, args:) }.to output(<<~EOS).to_stdout
==> example: 2.0
Installed (as dependency)
==> Installed Versions
original/tools/example 1.0 (0B)
EOS
end

describe "a missing installed cask directory" do
let(:cask) { Cask::Cask.new("example") { version "1.0" } }
let(:installed_path) { Cask::Caskroom.path/"example/1.0" }
let(:time) { 1_720_189_863 }

before do
allow(cask).to receive_messages(installed?: true, installed_version: "1.0", outdated?: false)
allow(Cask::Caskroom).to receive(:casks).and_return([])
allow(Cask::Tab).to receive(:for_cask).with(cask).and_return(
Cask::Tab.new(loaded_from_api: true, tabfile: TEST_FIXTURE_DIR/"cask_receipt.json", time:),
)
end

it "shows the missing path without --verbose" do
expect { described_class.info(cask, args:) }.to output(<<~EOS).to_stdout
==> example: 1.0
Installed (as dependency)
==> Installed Versions
example 1.0
#{installed_path} (does not exist)
EOS
end

it "shows the missing path once and the receipt with --verbose" do
verbose_args = Homebrew::Cmd::Info.new(["--verbose"]).args
expect { described_class.info(cask, args: verbose_args) }.to output(<<~EOS).to_stdout
==> example: 1.0
Installed (as dependency)
==> Installed Versions
example 1.0
#{installed_path} (does not exist)
Installed using the formulae.brew.sh API on #{Time.at(time).strftime("%Y-%m-%d at %H:%M:%S")}
EOS
end
end

Expand Down Expand Up @@ -273,6 +368,8 @@ def mock_cask_installed(cask_name)
allow(Cask::Caskroom).to receive(:casks).and_return([])

expected_output = <<~EOS
==> grouped-artifacts: 1.0
Not installed
==> Apps
Example.app -> Renamed.app
==> Fonts
Expand All @@ -289,8 +386,11 @@ def mock_cask_installed(cask_name)
Example.qlgenerator (Quick Look Plugin)
==> Artifacts
Example.pkg (Pkg)
==> Binaries
example
EOS
expect(described_class.artifact_info(cask)).to eq(expected_output.chomp)
expect { described_class.info(cask, args: Homebrew::Cmd::Info.new(["--verbose"]).args) }
.to output(expected_output).to_stdout
end

it "lists command wrappers under Binaries only with --verbose" do
Expand Down
Loading
Loading