Commit 98f84e9c authored by Eloy Duran's avatar Eloy Duran

Use Open4 in Executable. Indenter code by @ahoward, thanks!

parent bde1195c
......@@ -2,6 +2,9 @@ source "http://rubygems.org"
gem "colored"
gem "escape"
gem "open4"
# TODO why are these not in the gemspec yet?
gem "json"
gem "octokit"
......
......@@ -36,6 +36,7 @@ GEM
faraday_middleware (~> 0.8)
hashie (~> 1.2)
multi_json (~> 1.3)
open4 (1.3.0)
pry (0.9.9.6)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
......@@ -60,6 +61,7 @@ DEPENDENCIES
kicker
mocha-on-bacon
octokit
open4
pry
rake
rb-fsevent
......
......@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'xcodeproj', '~> 0.1.0'
s.add_runtime_dependency 'colored', '~> 1.2'
s.add_runtime_dependency 'escape', '~> 0.0.4'
s.add_runtime_dependency 'open4', '~> 1.3.0'
s.add_runtime_dependency 'rake', '~> 0.9.0'
s.add_development_dependency 'bacon', '~> 1.1'
......
require 'open4'
module Pod
module Executable
class Indenter < ::Array
attr_accessor :indent
attr_accessor :io
def initialize(io = nil, indent = ' ')
@io = io
@indent = indent
end
def <<(value)
super
ensure
@io << "#{ indent }#{ value }" if @io
end
end
def executable(name)
bin = `which #{name}`.strip
define_method(name) do |command|
......@@ -8,14 +26,15 @@ module Pod
end
full_command = "#{bin} #{command}"
if Config.instance.verbose?
puts "$ #{full_command}"
output = `#{full_command} 2>&1 | /usr/bin/tee /dev/tty`
puts " $ #{full_command}"
stdout, stderr = Indenter.new(STDOUT), Indenter.new(STDERR)
else
output = `#{full_command} 2>&1`
stdout, stderr = Indenter.new, Indenter.new
end
status = Open4.spawn(full_command, :stdout => stdout, :stderr => stderr, :status => true)
# TODO not sure that we should be silent in case of a failure.
puts "[!] Failed: #{full_command}".red unless Config.instance.silent? || $?.exitstatus.zero?
output
puts "[!] Failed: #{full_command}".red unless status.success? || Config.instance.silent?
stdout.join("\n") + stderr.join("\n") # TODO will this suffice?
end
private name
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