Class: SystemCommand::Result Private

Inherits:
Object
  • Object
show all
Includes:
Context
Defined in:
Library/Homebrew/system_command.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.

Result containing the output and exit status of a finished sub-process.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(command, output, status, secrets:) ⇒ Result

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 Result.


181
182
183
184
185
186
187
# File 'Library/Homebrew/system_command.rb', line 181

def initialize(command, output, status, secrets:)
  @command       = command
  @output        = output
  @status        = status
  @exit_status   = status.exitstatus
  @secrets       = secrets
end

Instance Attribute Details

#commandObject

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.


179
180
181
# File 'Library/Homebrew/system_command.rb', line 179

def command
  @command
end

#exit_statusObject

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.


179
180
181
# File 'Library/Homebrew/system_command.rb', line 179

def exit_status
  @exit_status
end

#statusObject

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.


179
180
181
# File 'Library/Homebrew/system_command.rb', line 179

def status
  @status
end

Instance Method Details

#assert_success!Object

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.


189
190
191
192
193
# File 'Library/Homebrew/system_command.rb', line 189

def assert_success!
  return if @status.success?

  raise ErrorDuringExecution.new(command, status: @status, output: @output, secrets: @secrets)
end

#merged_outputObject

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.


207
208
209
210
# File 'Library/Homebrew/system_command.rb', line 207

def merged_output
  @merged_output ||= @output.map { |_, line| line }
                            .join
end

#plistObject

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.


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'Library/Homebrew/system_command.rb', line 222

def plist
  @plist ||= begin
    output = stdout

    if /\A(?<garbage>.*?)<\?\s*xml/m =~ output
      output = output.sub(/\A#{Regexp.escape(garbage)}/m, "")
      warn_plist_garbage(garbage)
    end

    if %r{<\s*/\s*plist\s*>(?<garbage>.*?)\Z}m =~ output
      output = output.sub(/#{Regexp.escape(garbage)}\Z/, "")
      warn_plist_garbage(garbage)
    end

    Plist.parse_xml(output)
  end
end

#stderrObject

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.


201
202
203
204
205
# File 'Library/Homebrew/system_command.rb', line 201

def stderr
  @stderr ||= @output.select { |type,| type == :stderr }
                     .map { |_, line| line }
                     .join
end

#stdoutObject

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.


195
196
197
198
199
# File 'Library/Homebrew/system_command.rb', line 195

def stdout
  @stdout ||= @output.select { |type,| type == :stdout }
                     .map { |_, line| line }
                     .join
end

#success?Boolean

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:

  • (Boolean)

212
213
214
215
216
# File 'Library/Homebrew/system_command.rb', line 212

def success?
  return false if @exit_status.nil?

  @exit_status.zero?
end

#to_aryObject

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.


218
219
220
# File 'Library/Homebrew/system_command.rb', line 218

def to_ary
  [stdout, stderr, status]
end