From 8bee0555b96cc7a6e44c02bb9318a1acffd3ee46 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Wed, 11 Dec 2024 23:24:22 -0800 Subject: [PATCH 1/2] cask/info: send missing args after removing openstruct This seems like it was a bug before the recent change to remove OpenStruct from `Homebrew::CLI::Args` but it was failing silently before. Now we pass the args to the `Cask::Info.info` method so that when they eventually reach the `Utils::Analytics.output_analytics` method they are present as expected. Example error fragment: ```console $ set -e HOMEBREW_NO_ANALYTICS $ brew info iterm2 --cask --verbose ==> iterm2: 3.5.10 (auto_updates) https://iterm2.com/ Installed /usr/local/Caskroom/iterm2/3.5.4 (91.7MB) From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/i/iterm2.rb ==> Name iTerm2 ==> Description Terminal emulator as alternative to Apple's Terminal app ==> Artifacts iTerm.app (App) Error: undefined method `analytics?' for an instance of Homebrew::CLI::Args /usr/local/Homebrew/Library/Homebrew/utils/analytics.rb:248:in `output_analytics' /usr/local/Homebrew/Library/Homebrew/utils/analytics.rb:342:in `cask_output' /usr/local/Homebrew/Library/Homebrew/cask/info.rb:39:in `info' ``` --- Library/Homebrew/cask/info.rb | 6 +++--- Library/Homebrew/cmd/info.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cask/info.rb b/Library/Homebrew/cask/info.rb index 16515d665944d..3eaeabba45479 100644 --- a/Library/Homebrew/cask/info.rb +++ b/Library/Homebrew/cask/info.rb @@ -31,12 +31,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:) end sig { params(cask: Cask).returns(String) } diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 32fae43a1d3e0..7abc703422a7b 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -382,7 +382,7 @@ def dep_display_s(dep) def info_cask(cask) require "cask/info" - Cask::Info.info(cask) + Cask::Info.info(cask, args:) end end end From 9c0987c71c1ef378aad978c62f7a7c8aeb34db6a Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Thu, 12 Dec 2024 00:01:30 -0800 Subject: [PATCH 2/2] cask/info: update tests --- Library/Homebrew/cask/info.rb | 1 + Library/Homebrew/test/cask/info_spec.rb | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/info.rb b/Library/Homebrew/cask/info.rb index 3eaeabba45479..9273ac05bbc04 100644 --- a/Library/Homebrew/cask/info.rb +++ b/Library/Homebrew/cask/info.rb @@ -2,6 +2,7 @@ # frozen_string_literal: true require "json" +require "cmd/info" module Cask class Info diff --git a/Library/Homebrew/test/cask/info_spec.rb b/Library/Homebrew/test/cask/info_spec.rb index 20a5fa214cc6a..dda7abf46c563 100644 --- a/Library/Homebrew/test/cask/info_spec.rb +++ b/Library/Homebrew/test/cask/info_spec.rb @@ -3,6 +3,8 @@ 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" @@ -10,7 +12,7 @@ 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/ @@ -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 @@ -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 @@ -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 @@ -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/ @@ -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/ @@ -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/ @@ -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/ @@ -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/