Class: Hbc::SystemCommand::Result

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/cask/lib/hbc/system_command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, stdout, stderr, exit_status) ⇒ Result

Returns a new instance of Result



130
131
132
133
134
135
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 130

def initialize(command, stdout, stderr, exit_status)
  @command     = command
  @stdout      = stdout
  @stderr      = stderr
  @exit_status = exit_status
end

Instance Attribute Details

#commandObject

Returns the value of attribute command



128
129
130
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 128

def command
  @command
end

#exit_statusObject

Returns the value of attribute exit_status



128
129
130
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 128

def exit_status
  @exit_status
end

#stderrObject

Returns the value of attribute stderr



128
129
130
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 128

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout



128
129
130
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 128

def stdout
  @stdout
end

Class Method Details

._parse_plist(command, output) ⇒ Object

Raises:



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 161

def self._parse_plist(command, output)
  raise CaskError, "Empty plist input" unless output =~ /\S/
  output.sub!(/\A(.*?)(<\?\s*xml)/m, '\2')
  _warn_plist_garbage(command, Regexp.last_match[1]) if ARGV.debug?
  output.sub!(%r{(<\s*/\s*plist\s*>)(.*?)\Z}m, '\1')
  _warn_plist_garbage(command, Regexp.last_match[2])
  xml = Plist.parse_xml(output)
  unless xml.respond_to?(:keys) && !xml.keys.empty?
    raise CaskError, <<~EOS
      Empty result parsing plist output from command.
        command was:
        #{command}
        output we attempted to parse:
        #{output}
    EOS
  end
  xml
end

._warn_plist_garbage(command, garbage) ⇒ Object



153
154
155
156
157
158
159
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 153

def self._warn_plist_garbage(command, garbage)
  return true unless garbage =~ /\S/
  external = File.basename(command.first)
  lines = garbage.strip.split("\n")
  opoo "Non-XML stdout from #{external}:"
  $stderr.puts lines.map { |l| "    #{l}" }
end

Instance Method Details

#merged_outputObject



145
146
147
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 145

def merged_output
  @merged_output ||= @stdout + @stderr
end

#plistObject



137
138
139
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 137

def plist
  @plist ||= self.class._parse_plist(@command, @stdout.dup)
end

#success?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 141

def success?
  @exit_status.zero?
end

#to_sObject



149
150
151
# File 'Library/Homebrew/cask/lib/hbc/system_command.rb', line 149

def to_s
  @stdout
end