From 2d5ae645d9cc46af57aaaabbfe6bfb2db9f9e1bd Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 2 Jul 2018 09:05:49 +0100 Subject: [PATCH] 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