From 421eafaec8638e96fc46daf70f6a20242a058e10 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Tue, 25 Mar 2014 11:19:11 -0400 Subject: [PATCH] display artifact summary in `brew cask info` Per discussion with @drew-gross in closed issue #3280. Limitation: does not show link targets. --- lib/cask/cli/info.rb | 26 ++++++++++++++++++++------ lib/cask/dsl.rb | 36 ++++++++++++++++++++---------------- test/cask/cli/info_test.rb | 8 ++++++++ 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/lib/cask/cli/info.rb b/lib/cask/cli/info.rb index b3a5b2e09b1b..922579735a90 100644 --- a/lib/cask/cli/info.rb +++ b/lib/cask/cli/info.rb @@ -20,12 +20,13 @@ def self.info(cask) "Not installed" end - <<-PURPOSE.undent - #{cask}: #{cask.version} - #{cask.homepage} - #{installation} - #{github_info(cask)} - PURPOSE + <<-PURPOSE +#{cask}: #{cask.version} +#{cask.homepage} +#{installation} +#{github_info(cask)} +#{artifact_info(cask)} +PURPOSE end def self.github_info(cask) @@ -35,4 +36,17 @@ def self.github_info(cask) user, repo = tap.split "-" "https://github.com/#{user}/homebrew-#{repo}/commits/master/Casks/#{name}.rb" end + + def self.artifact_info(cask) + retval = '' + Cask::DSL::ClassMethods.ordinary_artifact_types.each do |type| + if cask.artifacts[type].length > 0 + retval = "#{Tty.blue}==>#{Tty.white} Contents#{Tty.reset}\n" unless retval.length > 0 + cask.artifacts[type].each do |artifact| + retval.concat " #{artifact.first} (#{type.to_s})\n" + end + end + end + retval.sub!(/\n\Z/, '') + end end diff --git a/lib/cask/dsl.rb b/lib/cask/dsl.rb index 597f6673df7a..136b3d5bf2a3 100644 --- a/lib/cask/dsl.rb +++ b/lib/cask/dsl.rb @@ -84,22 +84,26 @@ def caveats(*string, &block) end end - ARTIFACT_TYPES = [ - :link, - :prefpane, - :qlplugin, - :font, - :widget, - :service, - :colorpicker, - :binary, - :caskroom_only, - :input_method, - :screen_saver, - :install, - ] - - ARTIFACT_TYPES.each do |type| + def self.ordinary_artifact_types + @@ordinary_artifact_types ||= [ + :link, + :prefpane, + :qlplugin, + :font, + :widget, + :service, + :colorpicker, + :binary, + :input_method, + :screen_saver, + :install, + ] + end + + installable_artifact_types = ordinary_artifact_types + installable_artifact_types.push :caskroom_only + + installable_artifact_types.each do |type| define_method(type) do |*args| artifacts[type] << args end diff --git a/test/cask/cli/info_test.rb b/test/cask/cli/info_test.rb index 1142a8b36a2f..717b8b54a44b 100644 --- a/test/cask/cli/info_test.rb +++ b/test/cask/cli/info_test.rb @@ -9,6 +9,8 @@ http://example.com/local-caffeine Not installed https://github.com/phinze/homebrew-testcasks/commits/master/Casks/local-caffeine.rb + ==> Contents + Caffeine.app (link) CLIOUTPUT end @@ -20,10 +22,14 @@ http://example.com/local-caffeine Not installed https://github.com/phinze/homebrew-testcasks/commits/master/Casks/local-caffeine.rb + ==> Contents + Caffeine.app (link) local-transmission: 2.61 http://example.com/local-transmission Not installed https://github.com/phinze/homebrew-testcasks/commits/master/Casks/local-transmission.rb + ==> Contents + Transmission.app (link) CLIOUTPUT end @@ -35,6 +41,8 @@ http://example.com/local-caffeine Not installed https://github.com/phinze/homebrew-testcasks/commits/master/Casks/with-caveats.rb + ==> Contents + Caffeine.app (link) ==> Caveats Here are some things you might want to know.