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

cask/info: send missing args after removing openstruct #18917

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions Library/Homebrew/cask/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: true

require "json"
require "cmd/info"

module Cask
class Info
Expand Down Expand Up @@ -31,12 +32,12 @@ def self.get_info(cask)
output
end

sig { params(cask: Cask).void }
def self.info(cask)
sig { params(cask: Cask, args: Homebrew::Cmd::Info::Args).void }
def self.info(cask, args:)
puts get_info(cask)

require "utils/analytics"
::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new)
::Utils::Analytics.cask_output(cask, args:)
Comment on lines -39 to +40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was an existing bug that only came to light because of recent changes. It seems like by creating a new instance of the CLI args here that args.analytics? would always be falsey later on which doesn't seem to be the desired behavior. Now when the --analytics flag is set it will get passed to Utils::Analytics.cask_output the same way it already gets passed to Utils::Analytics.formula_output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! We might want to add some guardrails around where/how Args can be instantiated 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's probably not necessary unless it's really simple to implement since I doubt that we'll ever run into the same problem again.

end

sig { params(cask: Cask).returns(String) }
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
def info_cask(cask)
require "cask/info"

Cask::Info.info(cask)
Cask::Info.info(cask, args:)

Check warning on line 385 in Library/Homebrew/cmd/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/info.rb#L385

Added line #L385 was not covered by tests
end
end
end
Expand Down
20 changes: 11 additions & 9 deletions Library/Homebrew/test/cask/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
require "utils"

RSpec.describe Cask::Info, :cask do
let(:args) { instance_double(Homebrew::Cmd::Info::Args) }

before do
# Prevent unnecessary network requests in `Utils::Analytics.cask_output`
ENV["HOMEBREW_NO_ANALYTICS"] = "1"
end

it "displays some nice info about the specified Cask" do
expect do
described_class.info(Cask::CaskLoader.load("local-transmission"))
described_class.info(Cask::CaskLoader.load("local-transmission"), args:)
end.to output(<<~EOS).to_stdout
==> local-transmission: 2.61
https://transmissionbt.com/
Expand All @@ -27,7 +29,7 @@

it "prints cask dependencies if the Cask has any" do
expect do
described_class.info(Cask::CaskLoader.load("with-depends-on-cask-multiple"))
described_class.info(Cask::CaskLoader.load("with-depends-on-cask-multiple"), args:)
end.to output(<<~EOS).to_stdout
==> with-depends-on-cask-multiple: 1.2.3
https://brew.sh/with-depends-on-cask-multiple
Expand All @@ -46,7 +48,7 @@

it "prints cask and formulas dependencies if the Cask has both" do
expect do
described_class.info(Cask::CaskLoader.load("with-depends-on-everything"))
described_class.info(Cask::CaskLoader.load("with-depends-on-everything"), args:)
end.to output(<<~EOS).to_stdout
==> with-depends-on-everything: 1.2.3
https://brew.sh/with-depends-on-everything
Expand All @@ -65,7 +67,7 @@

it "prints auto_updates if the Cask has `auto_updates true`" do
expect do
described_class.info(Cask::CaskLoader.load("with-auto-updates"))
described_class.info(Cask::CaskLoader.load("with-auto-updates"), args:)
end.to output(<<~EOS).to_stdout
==> with-auto-updates: 1.0 (auto_updates)
https://brew.sh/autoupdates
Expand All @@ -82,7 +84,7 @@

it "prints caveats if the Cask provided one" do
expect do
described_class.info(Cask::CaskLoader.load("with-caveats"))
described_class.info(Cask::CaskLoader.load("with-caveats"), args:)
end.to output(<<~EOS).to_stdout
==> with-caveats: 1.2.3
https://brew.sh/
Expand All @@ -109,7 +111,7 @@

it 'does not print "Caveats" section divider if the caveats block has no output' do
expect do
described_class.info(Cask::CaskLoader.load("with-conditional-caveats"))
described_class.info(Cask::CaskLoader.load("with-conditional-caveats"), args:)
end.to output(<<~EOS).to_stdout
==> with-conditional-caveats: 1.2.3
https://brew.sh/
Expand All @@ -126,7 +128,7 @@

it "prints languages specified in the Cask" do
expect do
described_class.info(Cask::CaskLoader.load("with-languages"))
described_class.info(Cask::CaskLoader.load("with-languages"), args:)
end.to output(<<~EOS).to_stdout
==> with-languages: 1.2.3
https://brew.sh/
Expand All @@ -145,7 +147,7 @@

it 'does not print "Languages" section divider if the languages block has no output' do
expect do
described_class.info(Cask::CaskLoader.load("without-languages"))
described_class.info(Cask::CaskLoader.load("without-languages"), args:)
end.to output(<<~EOS).to_stdout
==> without-languages: 1.2.3
https://brew.sh/
Expand Down Expand Up @@ -173,7 +175,7 @@
expect(Cask::Tab).to receive(:for_cask).with(cask).and_return(tab)

expect do
described_class.info(cask)
described_class.info(cask, args:)
end.to output(<<~EOS).to_stdout
==> local-transmission: 2.61
https://transmissionbt.com/
Expand Down
Loading