Commit f377c313 authored by Florian R. Hanke's avatar Florian R. Hanke

[Executable] Extract output handling to make it testable.

parent 179600e2
......@@ -49,21 +49,9 @@ module Pod
bin = `which #{executable}`.strip
raise Informative, "Unable to locate the executable `#{executable}`" if bin.empty?
require 'shellwords'
command = command.map(&:to_s)
full_command = "#{bin} #{command.join(' ')}"
UI.message("$ #{full_command}") if Config.instance.verbose?
output = StringIO.new
indented = Indenter.new(output)
status = with_verbose do
spawn(bin, command) do |line|
indented << line
end
end
with_output(bin, command.map(&:to_s), output) do |full_command, status|
unless status.success?
if raise_on_failure
raise Informative, "#{full_command}\n\n#{output.string}"
......@@ -71,12 +59,32 @@ module Pod
UI.message("[!] Failed: #{full_command}".red)
end
end
end
output.string
end
private
#
#
def self.with_output bin, command, output
full_command = "#{bin} #{command.join(' ')}"
UI.message("$ #{full_command}") if Config.instance.verbose?
indented = Indenter.new(output)
status = with_verbose do
spawn(bin, command) do |line|
indented.write line
end
end
yield full_command, status if block_given?
status
end
# Spawn a subprocess.
#
# @param bin [String] Name of the binary to use.
......@@ -150,8 +158,12 @@ module Pod
#
# @return [void]
#
def <<(value)
@io << "#{ indent }#{ value }"
def write(value)
@io.write "#{ indent }#{ value }"
end
def flush
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment