Fix _stanza.

This commit is contained in:
Markus Reiter 2017-08-04 14:59:18 +02:00
parent 53ecdd843f
commit b0c98ba631
6 changed files with 43 additions and 10 deletions

View File

@ -31,6 +31,10 @@ module Hbc
@directives = directives @directives = directives
end end
def to_h
directives.to_h
end
private private
def dispatch_uninstall_directives(**options) def dispatch_uninstall_directives(**options)

View File

@ -73,6 +73,12 @@ module Hbc
def summarize def summarize
path.relative_path_from(cask.staged_path).to_s path.relative_path_from(cask.staged_path).to_s
end end
def to_h
{ path: path.relative_path_from(cask.staged_path).to_s }.tap do |h|
h[:args] = args unless is_a?(ManualInstaller)
end
end
end end
end end
end end

View File

@ -35,6 +35,12 @@ module Hbc
@target = self.class.resolve_target(target) @target = self.class.resolve_target(target)
end end
def to_a
[@source_string].tap do |ary|
ary << { target: @target_string } unless @target_string.empty?
end
end
def summarize def summarize
target_string = @target_string.empty? ? "" : " -> #{@target_string}" target_string = @target_string.empty? ? "" : " -> #{@target_string}"
"#{@source_string}#{target_string}" "#{@source_string}#{target_string}"

View File

@ -14,6 +14,10 @@ module Hbc
def initialize(cask) def initialize(cask)
super(cask) super(cask)
end end
def to_a
[true]
end
end end
end end
end end

View File

@ -3,7 +3,7 @@ module Hbc
class InternalStanza < AbstractInternalCommand class InternalStanza < AbstractInternalCommand
# Syntax # Syntax
# #
# brew cask _stanza <stanza_name> [ --table | --yaml | --inspect | --quiet ] [ <cask_token> ... ] # brew cask _stanza <stanza_name> [ --quiet ] [ --table | --yaml ] [ <cask_token> ... ]
# #
# If no tokens are given, then data for all Casks is returned. # If no tokens are given, then data for all Casks is returned.
# #
@ -14,11 +14,11 @@ module Hbc
# Examples # Examples
# #
# brew cask _stanza appcast --table # brew cask _stanza appcast --table
# brew cask _stanza app --table alfred google-chrome adium voicemac logisim vagrant # brew cask _stanza app --table alfred google-chrome adium vagrant
# brew cask _stanza url --table alfred google-chrome adium voicemac logisim vagrant # brew cask _stanza url --table alfred google-chrome adium vagrant
# brew cask _stanza version --table alfred google-chrome adium voicemac logisim vagrant # brew cask _stanza version --table alfred google-chrome adium vagrant
# brew cask _stanza artifacts --table --inspect alfred google-chrome adium voicemac logisim vagrant # brew cask _stanza artifacts --table alfred google-chrome adium vagrant
# brew cask _stanza artifacts --table --yaml alfred google-chrome adium voicemac logisim vagrant # brew cask _stanza artifacts --table --yaml alfred google-chrome adium vagrant
# #
ARTIFACTS = ARTIFACTS =
@ -43,7 +43,6 @@ module Hbc
@stanza = args.shift.to_sym @stanza = args.shift.to_sym
@format = :to_yaml if yaml? @format = :to_yaml if yaml?
@format = :inspect if inspect?
end end
def run def run
@ -81,11 +80,25 @@ module Hbc
next next
end end
value = value.fetch(artifact_name).to_a.flatten if artifact_name if stanza == :artifacts
value = Hash[
value.map do |k, v|
v = v.map do |a|
next a.to_a if a.respond_to?(:to_a)
next a.to_h if a.respond_to?(:to_h)
a
end
[k, v]
end
]
value = value.fetch(artifact_name) if artifact_name
end
if format if format
puts value.send(format) puts value.send(format)
elsif artifact_name || value.is_a?(Symbol) elsif value.is_a?(Symbol)
puts value.inspect puts value.inspect
else else
puts value.to_s puts value.to_s

View File

@ -8,7 +8,7 @@ describe "conflicts_with", :cask do
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-conflicts-with.rb") Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-conflicts-with.rb")
} }
it "installs the dependency of a Cask and the Cask itself", :focus do it "installs the dependency of a Cask and the Cask itself" do
Hbc::Installer.new(local_caffeine).install Hbc::Installer.new(local_caffeine).install
expect(local_caffeine).to be_installed expect(local_caffeine).to be_installed