Class: Cask::Cmd::InternalStanza Private

Inherits:
AbstractInternalCommand show all
Defined in:
Library/Homebrew/cask/cmd/internal_stanza.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Implementation of the brew cask _stanza command.

Constant Summary collapse

ARTIFACTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Syntax

brew cask _stanza <stanza_name> [ --quiet ] [ --table | --yaml ] [ <cask_token> ... ]

If no tokens are given, then data for all casks is returned.

The pseudo-stanza "artifacts" is available.

On failure, a blank line is returned on the standard output.

(DSL::ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) +
DSL::ARTIFACT_BLOCK_CLASSES.map(&:dsl_key)).freeze

Constants inherited from AbstractCommand

AbstractCommand::OPTIONS

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractInternalCommand

command_name, visible?

Methods inherited from AbstractCommand

abstract?, banner_headline, command_name, help, max_named, run, short_description, visible?

Methods included from Homebrew::Search

#query_regexp, #search_casks, #search_descriptions, #search_formulae, #search_taps

Constructor Details

#initializeInternalStanza

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of InternalStanza.

Raises:


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'Library/Homebrew/cask/cmd/internal_stanza.rb', line 66

def initialize(*)
  super

  named = args.named.dup
  @stanza = named.shift.to_sym
  args.freeze_named_args!(named)

  @format = :to_yaml if args.yaml?

  return if DSL::DSL_METHODS.include?(stanza)

  raise UsageError, <<~EOS
    Unknown/unsupported stanza: '#{stanza}'
    Check cask reference for supported stanzas.
  EOS
end

Class Method Details

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


31
32
33
# File 'Library/Homebrew/cask/cmd/internal_stanza.rb', line 31

def self.banner_args
  " <stanza_name> [<cask>]"
end

.descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'Library/Homebrew/cask/cmd/internal_stanza.rb', line 35

def self.description
  <<~EOS
    Extract and render a specific stanza for the given <cask>.

    Examples:
      `brew cask _stanza appcast   --table`
      `brew cask _stanza app       --table           alfred google-chrome vagrant`
      `brew cask _stanza url       --table           alfred google-chrome vagrant`
      `brew cask _stanza version   --table           alfred google-chrome vagrant`
      `brew cask _stanza artifacts --table           alfred google-chrome vagrant`
      `brew cask _stanza artifacts --table --yaml    alfred google-chrome vagrant`
  EOS
end

.min_namedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


27
28
29
# File 'Library/Homebrew/cask/cmd/internal_stanza.rb', line 27

def self.min_named
  1
end

.parserObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


49
50
51
52
53
54
55
56
57
58
59
60
# File 'Library/Homebrew/cask/cmd/internal_stanza.rb', line 49

def self.parser
  super do
    switch "--table",
           description: "Print stanza in table format."
    switch "--quiet",
           description: ""
    switch "--yaml",
           description: ""
    switch "--inspect",
           description: ""
  end
end

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'Library/Homebrew/cask/cmd/internal_stanza.rb', line 83

def run
  if ARTIFACTS.include?(stanza)
    artifact_name = stanza
    @stanza = :artifacts
  end

  casks(alternative: -> { Cask.to_a }).each do |cask|
    print "#{cask}\t" if args.table?

    begin
      value = cask.send(stanza)
    rescue
      opoo "failure calling '#{stanza}' on Cask '#{cask}'" unless args.quiet?
      puts ""
      next
    end

    if stanza == :artifacts
      value = Hash[value.map { |v| [v.class.dsl_key, v.to_s] }]
      value = value[artifact_name] if artifact_name
    end

    if value.nil? || (value.respond_to?(:empty?) && value.empty?)
      stanza_name = artifact_name || stanza
      raise CaskError, "no such stanza '#{stanza_name}' on Cask '#{cask}'"
    end

    if format
      puts value.send(format)
    elsif value.is_a?(Symbol)
      puts value.inspect
    else
      puts value.to_s
    end
  end
end