From 2d5ae645d9cc46af57aaaabbfe6bfb2db9f9e1bd Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 2 Jul 2018 09:05:49 +0100 Subject: [PATCH 1/9] Add basic JSON option to brew cask $ brew cask info --json --- Library/Homebrew/cask/lib/hbc/cask.rb | 21 +++++++++++++++++++++ Library/Homebrew/cask/lib/hbc/cli/info.rb | 15 ++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 8ec40f68dd..bff705265b 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -129,5 +129,26 @@ module Hbc odebug "Cask instance method '#{method}':", send(method).to_yaml end end + + def to_hash + hsh = { + "name" => name, + "homepage" => homepage, + "url" => url, + "appcast" => appcast, + "version" => version, + "sha256" => sha256, + "artifacts" => artifacts, + "caveats" => caveats, + "depends_on" => depends_on, + "conflicts_with" => conflicts_with, + "container" => container, + "gpg" => gpg, + "accessibility_access" => accessibility_access, + "auto_updates" => auto_updates + } + + hsh + end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 991f0534ae..97a2e3e49c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -1,15 +1,24 @@ +require "json" + module Hbc class CLI class Info < AbstractCommand + option "--json", :json, false + def initialize(*) super raise CaskUnspecifiedError if args.empty? end def run - casks.each do |cask| - odebug "Getting info for Cask #{cask}" - self.class.info(cask) + if json? + json = casks.map(&:to_hash) + puts JSON.generate(json) + else + casks.each do |cask| + odebug "Getting info for Cask #{cask}" + self.class.info(cask) + end end end From 0bfc6bd490d0ee12624c1c20f7b525bc1939a744 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 2 Jul 2018 10:13:25 +0100 Subject: [PATCH 2/9] Improve format of git cask info --json output --- .../cask/lib/hbc/artifact/abstract_flight_block.rb | 8 ++++---- Library/Homebrew/cask/lib/hbc/cask.rb | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb index a3075ff409..54267fccb1 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb @@ -26,6 +26,10 @@ module Hbc 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) @@ -37,10 +41,6 @@ module Hbc return if (block = directives[dsl_key]).nil? 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/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index bff705265b..9e51d92d76 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -138,7 +138,7 @@ module Hbc "appcast" => appcast, "version" => version, "sha256" => sha256, - "artifacts" => artifacts, + "artifacts" => {}, "caveats" => caveats, "depends_on" => depends_on, "conflicts_with" => conflicts_with, @@ -148,6 +148,12 @@ module Hbc "auto_updates" => auto_updates } + artifacts.each do |a| + hsh["artifacts"][a.class.english_name] = a.summarize + end + + hsh["conflicts_with"] = [] if hsh["conflicts_with"] == nil + hsh end end From 22b3102fbe126be7f58e4d4a70214bf62d07bc09 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 2 Jul 2018 10:32:02 +0100 Subject: [PATCH 3/9] Add version number to cask json option Old: $ brew cask info --json New: $ brew cask info --json-v1 --- Library/Homebrew/cask/lib/hbc/cli/info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 97a2e3e49c..076d2f5a23 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -3,7 +3,7 @@ require "json" module Hbc class CLI class Info < AbstractCommand - option "--json", :json, false + option "--json-v1", :json, false def initialize(*) super From b548dbde973479ec5537a043b570047423318f7b Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 2 Jul 2018 10:46:41 +0100 Subject: [PATCH 4/9] Fix style --- Library/Homebrew/cask/lib/hbc/cask.rb | 4 ++-- Library/Homebrew/cask/lib/hbc/cli/info.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 9e51d92d76..9402e8eec1 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -145,14 +145,14 @@ module Hbc "container" => container, "gpg" => gpg, "accessibility_access" => accessibility_access, - "auto_updates" => auto_updates + "auto_updates" => auto_updates, } artifacts.each do |a| hsh["artifacts"][a.class.english_name] = a.summarize end - hsh["conflicts_with"] = [] if hsh["conflicts_with"] == nil + hsh["conflicts_with"] = [] if hsh["conflicts_with"].nil? hsh end diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 076d2f5a23..7be3a3a03a 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -4,7 +4,7 @@ module Hbc class CLI class Info < AbstractCommand option "--json-v1", :json, false - + def initialize(*) super raise CaskUnspecifiedError if args.empty? From 7e5addfb22661814a10253648719be9f4f8041dd Mon Sep 17 00:00:00 2001 From: alexbostock Date: Wed, 4 Jul 2018 15:03:31 +0100 Subject: [PATCH 5/9] Add version number to cask JSON option `$ brew cask info --json=v1 ` instead of `$ brew cask info --json ` --- Library/Homebrew/cask/lib/hbc/cli/info.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 7be3a3a03a..770723e9de 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -3,7 +3,7 @@ require "json" module Hbc class CLI class Info < AbstractCommand - option "--json-v1", :json, false + option "--json=VERSION", :json def initialize(*) super @@ -11,9 +11,8 @@ module Hbc end def run - if json? - json = casks.map(&:to_hash) - puts JSON.generate(json) + if json == "v1" + puts JSON.generate(casks.map(&:to_hash)) else casks.each do |cask| odebug "Getting info for Cask #{cask}" From 296dd5ecb2910bfa952c315ec23550a6fb012679 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Wed, 4 Jul 2018 15:08:32 +0100 Subject: [PATCH 6/9] Fix format of cask JSON output --- Library/Homebrew/cask/lib/hbc/cask.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 9402e8eec1..58ca6453ce 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -138,22 +138,24 @@ module Hbc "appcast" => appcast, "version" => version, "sha256" => sha256, - "artifacts" => {}, + "artifacts" => artifacts.map do |a| + if a.methods.include? :to_a + a.to_a + elsif a.methods.include? :to_h + a.to_h + else + a + end + end, "caveats" => caveats, "depends_on" => depends_on, - "conflicts_with" => conflicts_with, + "conflicts_with" => conflicts_with.to_a, "container" => container, "gpg" => gpg, "accessibility_access" => accessibility_access, "auto_updates" => auto_updates, } - artifacts.each do |a| - hsh["artifacts"][a.class.english_name] = a.summarize - end - - hsh["conflicts_with"] = [] if hsh["conflicts_with"].nil? - hsh end end From 7fea44ae46454da468882a4fd14e702bdd5134fe Mon Sep 17 00:00:00 2001 From: alexbostock Date: Tue, 17 Jul 2018 10:04:17 +0100 Subject: [PATCH 7/9] Tidy up --- Library/Homebrew/cask/lib/hbc/cask.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 58ca6453ce..533c9f7a9c 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -131,7 +131,7 @@ module Hbc end def to_hash - hsh = { + { "name" => name, "homepage" => homepage, "url" => url, @@ -139,7 +139,7 @@ module Hbc "version" => version, "sha256" => sha256, "artifacts" => artifacts.map do |a| - if a.methods.include? :to_a + if a.respond_to? :to_a a.to_a elsif a.methods.include? :to_h a.to_h @@ -155,8 +155,6 @@ module Hbc "accessibility_access" => accessibility_access, "auto_updates" => auto_updates, } - - hsh end end end From 3fd1e914fd783388e9d59b504cd6a2cd8850c415 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Tue, 17 Jul 2018 10:56:44 +0100 Subject: [PATCH 8/9] Fix details in cask command --- .../cask/lib/hbc/artifact/abstract_flight_block.rb | 8 ++++---- Library/Homebrew/cask/lib/hbc/cask.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb index 54267fccb1..a3075ff409 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb @@ -26,10 +26,6 @@ module Hbc 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) @@ -41,6 +37,10 @@ module Hbc return if (block = directives[dsl_key]).nil? 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/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 533c9f7a9c..9bbbe6c01d 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -139,10 +139,10 @@ module Hbc "version" => version, "sha256" => sha256, "artifacts" => artifacts.map do |a| - if a.respond_to? :to_a - a.to_a - elsif a.methods.include? :to_h + if a.respond_to? :to_h a.to_h + elsif a.respond_to? :to_a + a.to_a else a end From 49bae9b619d6f94560ba82774e406baa53638898 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Tue, 17 Jul 2018 11:12:04 +0100 Subject: [PATCH 9/9] Rename to_hash method --- Library/Homebrew/cask/lib/hbc/cask.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/info.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 9bbbe6c01d..a2f2a08787 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -130,7 +130,7 @@ module Hbc end end - def to_hash + def to_h { "name" => name, "homepage" => homepage, diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 770723e9de..340a90daa5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -12,7 +12,7 @@ module Hbc def run if json == "v1" - puts JSON.generate(casks.map(&:to_hash)) + puts JSON.generate(casks.map(&:to_h)) else casks.each do |cask| odebug "Getting info for Cask #{cask}"