Class: Hbc::CLI::InternalStanza

Inherits:
AbstractInternalCommand show all
Defined in:
Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb

Constant Summary collapse

ARTIFACTS =

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.

Examples

brew cask _stanza appcast   --table
brew cask _stanza app       --table           alfred google-chrome adium vagrant
brew cask _stanza url       --table           alfred google-chrome adium vagrant
brew cask _stanza version   --table           alfred google-chrome adium vagrant
brew cask _stanza artifacts --table           alfred google-chrome adium vagrant
brew cask _stanza artifacts --table --yaml    alfred google-chrome adium vagrant
DSL::ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) +
DSL::ARTIFACT_BLOCK_CLASSES.map(&:dsl_key)

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?, command_name, needs_init?, run, visible

Methods included from Options

included, #process_arguments

Constructor Details

#initializeInternalStanza

Returns a new instance of InternalStanza

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb', line 39

def initialize(*)
  super
  raise ArgumentError, "No stanza given." if args.empty?

  @stanza = args.shift.to_sym

  @format = :to_yaml if yaml?

  return if DSL::DSL_METHODS.include?(stanza)
  raise ArgumentError,
    <<~EOS
      Unknown/unsupported stanza: '#{stanza}'
      Check Cask reference for supported stanzas.
    EOS
end

Class Method Details

.helpObject



92
93
94
# File 'Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb', line 92

def self.help
  "extract and render a specific stanza for the given Casks"
end

Instance Method Details

#runObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb', line 55

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

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

    begin
      value = cask.send(stanza)
    rescue StandardError
      opoo "failure calling '#{stanza}' on Cask '#{cask}'" unless 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 ? 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