Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 98f84e9c38d2a79e54b81499cfaa8bd9992f4ce4 1 parent bde1195
Eloy Durán alloy authored
3  Gemfile
View
@@ -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"
2  Gemfile.lock
View
@@ -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
1  cocoapods.gemspec
View
@@ -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'
29 lib/cocoapods/executable.rb
View
@@ -1,5 +1,23 @@
+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 @@ def executable(name)
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
Please sign in to comment.
Something went wrong with that request. Please try again.