[UserInterface] Add output_io attribute to redirect UI output

parent 9344a3f2
...@@ -20,6 +20,10 @@ module Pod ...@@ -20,6 +20,10 @@ module Pod
attr_accessor :title_level attr_accessor :title_level
attr_accessor :warnings attr_accessor :warnings
# @return [IO] IO object to which UI output will be directed.
#
attr_accessor :output_io
# @return [Bool] Whether the wrapping of the strings to the width of the # @return [Bool] Whether the wrapping of the strings to the width of the
# terminal should be disabled. # terminal should be disabled.
# #
...@@ -322,7 +326,12 @@ module Pod ...@@ -322,7 +326,12 @@ module Pod
# The message to print. # The message to print.
# #
def puts(message = '') def puts(message = '')
STDOUT.puts(message) unless config.silent? return if config.silent?
begin
(output_io || STDOUT).puts(message)
rescue Errno::EPIPE
exit 0
end
end end
# prints a message followed by a new line unless config is silent. # prints a message followed by a new line unless config is silent.
...@@ -331,7 +340,12 @@ module Pod ...@@ -331,7 +340,12 @@ module Pod
# The message to print. # The message to print.
# #
def print(message) def print(message)
STDOUT.print(message) unless config.silent? return if config.silent?
begin
(output_io || STDOUT).print(message)
rescue Errno::EPIPE
exit 0
end
end end
# gets input from $stdin # gets input from $stdin
......
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