diff --git a/Library/Homebrew/cask/artifact/abstract_artifact.rb b/Library/Homebrew/cask/artifact/abstract_artifact.rb index 5c1abb3ffd..25b6f02833 100644 --- a/Library/Homebrew/cask/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/artifact/abstract_artifact.rb @@ -1,6 +1,8 @@ # typed: false # frozen_string_literal: true +require "active_support/core_ext/object/deep_dup" + module Cask module Artifact # Abstract superclass for all artifacts. @@ -127,8 +129,9 @@ module Cask attr_reader :cask - def initialize(cask) + def initialize(cask, *dsl_args) @cask = cask + @dsl_args = dsl_args.deep_dup end def config @@ -139,6 +142,10 @@ module Cask def to_s "#{summarize} (#{self.class.english_name})" end + + def to_args + @dsl_args.reject(&:blank?) + end end end end diff --git a/Library/Homebrew/cask/artifact/abstract_flight_block.rb b/Library/Homebrew/cask/artifact/abstract_flight_block.rb index 1695a257a5..eccdb10cab 100644 --- a/Library/Homebrew/cask/artifact/abstract_flight_block.rb +++ b/Library/Homebrew/cask/artifact/abstract_flight_block.rb @@ -32,6 +32,10 @@ module Cask abstract_phase(self.class.uninstall_dsl_key) end + def summarize + directives.keys.map(&:to_s).join(", ") + end + private def class_for_dsl_key(dsl_key) @@ -44,10 +48,6 @@ module Cask class_for_dsl_key(dsl_key).new(cask).instance_eval(&block) end - - def summarize - directives.keys.map(&:to_s).join(", ") - end end end end diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 2c8489828c..b5100bff15 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -40,7 +40,7 @@ module Cask def initialize(cask, directives) directives.assert_valid_keys!(*ORDERED_DIRECTIVES) - super(cask) + super(cask, **directives) directives[:signal] = Array(directives[:signal]).flatten.each_slice(2).to_a @directives = directives diff --git a/Library/Homebrew/cask/artifact/installer.rb b/Library/Homebrew/cask/artifact/installer.rb index 95c57418f4..2238bc075a 100644 --- a/Library/Homebrew/cask/artifact/installer.rb +++ b/Library/Homebrew/cask/artifact/installer.rb @@ -72,7 +72,7 @@ module Cask attr_reader :path, :args def initialize(cask, **args) - super(cask) + super(cask, **args) if args.key?(:manual) @path = Pathname(args[:manual]) diff --git a/Library/Homebrew/cask/artifact/pkg.rb b/Library/Homebrew/cask/artifact/pkg.rb index dd3a9447bf..9c3ef09a13 100644 --- a/Library/Homebrew/cask/artifact/pkg.rb +++ b/Library/Homebrew/cask/artifact/pkg.rb @@ -23,7 +23,7 @@ module Cask end def initialize(cask, path, **stanza_options) - super(cask) + super(cask, path, **stanza_options) @path = cask.staged_path.join(path) @stanza_options = stanza_options end diff --git a/Library/Homebrew/cask/artifact/relocated.rb b/Library/Homebrew/cask/artifact/relocated.rb index 612a0c7420..dd529b5dba 100644 --- a/Library/Homebrew/cask/artifact/relocated.rb +++ b/Library/Homebrew/cask/artifact/relocated.rb @@ -42,12 +42,13 @@ module Cask attr_reader :source, :target sig { - params(cask: Cask, source: T.nilable(T.any(String, Pathname)), target: T.nilable(T.any(String, Pathname))) + params(cask: Cask, source: T.nilable(T.any(String, Pathname)), target_hash: String) .void } - def initialize(cask, source, target: nil) - super(cask) + def initialize(cask, source, **target_hash) + super(cask, source, **target_hash) + target = target_hash[:target] @source_string = source.to_s @target_string = target.to_s source = cask.staged_path.join(source) diff --git a/Library/Homebrew/cask/artifact/stage_only.rb b/Library/Homebrew/cask/artifact/stage_only.rb index b475b00a86..3c5f10b639 100644 --- a/Library/Homebrew/cask/artifact/stage_only.rb +++ b/Library/Homebrew/cask/artifact/stage_only.rb @@ -14,7 +14,7 @@ module Cask def self.from_args(cask, *args) raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") if args != [true] - new(cask) + new(cask, true) end sig { returns(T::Array[T::Boolean]) } diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index d347e27ac3..88f453bb31 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -235,7 +235,7 @@ module Cask "installed" => versions.last, "outdated" => outdated?, "sha256" => sha256, - "artifacts" => artifacts.map(&method(:to_h_gsubs)), + "artifacts" => artifacts_list, "caveats" => (to_h_string_gsubs(caveats) unless caveats.empty?), "depends_on" => depends_on, "conflicts_with" => conflicts_with, @@ -281,6 +281,19 @@ module Cask private + def artifacts_list + artifacts.map do |artifact| + if artifact.is_a? Artifact::AbstractFlightBlock + { type: artifact.summarize } + else + { + type: artifact.class.dsl_key, + args: to_h_gsubs(artifact.to_args), + } + end + end + end + def to_h_string_gsubs(string) string.to_s .gsub(Dir.home, "$HOME") diff --git a/Library/Homebrew/test/cask/cmd/list_spec.rb b/Library/Homebrew/test/cask/cmd/list_spec.rb index 0ce95eb216..2a7af5d90f 100644 --- a/Library/Homebrew/test/cask/cmd/list_spec.rb +++ b/Library/Homebrew/test/cask/cmd/list_spec.rb @@ -106,13 +106,19 @@ describe Cask::Cmd::List, :cask do "outdated": false, "sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94", "artifacts": [ - [ - "Caffeine.app" - ], { - "trash": "$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist", - "signal": { - } + "type": "app", + "args": [ + "Caffeine.app" + ] + }, + { + "type": "zap", + "args": [ + { + "trash": "$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist" + } + ] } ], "caveats": null, @@ -140,9 +146,12 @@ describe Cask::Cmd::List, :cask do "outdated": false, "sha256": "e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68", "artifacts": [ - [ - "Transmission.app" - ] + { + "type": "app", + "args": [ + "Transmission.app" + ] + } ], "caveats": null, "depends_on": { @@ -172,9 +181,12 @@ describe Cask::Cmd::List, :cask do "outdated": false, "sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94", "artifacts": [ - [ - "Caffeine.app" - ] + { + "type": "app", + "args": [ + "Caffeine.app" + ] + } ], "caveats": null, "depends_on": { @@ -201,9 +213,12 @@ describe Cask::Cmd::List, :cask do "outdated": false, "sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", "artifacts": [ - [ - "ThirdParty.app" - ] + { + "type": "app", + "args": [ + "ThirdParty.app" + ] + } ], "caveats": null, "depends_on": {