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