Commit d3e2778e authored by Fabio Pelosin's avatar Fabio Pelosin

[Command::IPC] Use ASCII CR+LF to signal the end of output

parent e65c2ee5
...@@ -5,6 +5,10 @@ module Pod ...@@ -5,6 +5,10 @@ module Pod
self.abstract_command = true self.abstract_command = true
self.summary = 'Inter-process communication' self.summary = 'Inter-process communication'
def output_pipe
STDOUT
end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
class Spec < IPC class Spec < IPC
...@@ -25,7 +29,7 @@ module Pod ...@@ -25,7 +29,7 @@ module Pod
def run def run
spec = Specification.from_file(@path) spec = Specification.from_file(@path)
UI.puts spec.to_yaml output_pipe.puts spec.to_yaml
end end
end end
...@@ -50,7 +54,7 @@ module Pod ...@@ -50,7 +54,7 @@ module Pod
def run def run
podfile = Pod::Podfile.from_file(@path) podfile = Pod::Podfile.from_file(@path)
UI.puts podfile.to_yaml output_pipe.puts podfile.to_yaml
end end
end end
...@@ -89,7 +93,7 @@ module Pod ...@@ -89,7 +93,7 @@ module Pod
next next
end end
end end
UI.puts result.to_yaml output_pipe.puts result.to_yaml
end end
end end
...@@ -98,39 +102,38 @@ module Pod ...@@ -98,39 +102,38 @@ module Pod
class Repl < IPC class Repl < IPC
LISTENING_STRING = '>>> @LISTENING <<<' END_OF_OUTPUT_SIGNAL = "\n\r"
self.summary = 'The repl listens to commands on standard input.' self.summary = 'The repl listens to commands on standard input.'
self.description = <<-DESC self.description = <<-DESC
The repl listens to commands on standard input and prints their The repl listens to commands on standard input and prints their
result to standard output. result to standard output.
It accepts all the other ipc subcommands. The repl will signal when It accepts all the other ipc subcommands. The repl will signal the
it is ready to receive a new command with the `#{LISTENING_STRING}` end of output with the the ASCII CR+LF `\\n\\r`.
string.
DESC DESC
def run def run
salute print_version
signal_end_of_output
listen listen
end end
def salute def print_version
UI.puts "version: '#{Pod::VERSION}'" output_pipe.puts "version: '#{Pod::VERSION}'"
end
def signal_end_of_output
output_pipe.puts(END_OF_OUTPUT_SIGNAL)
STDOUT.flush
end end
def listen def listen
signal_ready
while repl_command = STDIN.gets while repl_command = STDIN.gets
execute_repl_command(repl_command) execute_repl_command(repl_command)
end end
end end
def signal_ready
UI.puts LISTENING_STRING
STDOUT.flush
end
def execute_repl_command(repl_command) def execute_repl_command(repl_command)
if (repl_command != "\n") if (repl_command != "\n")
repl_commands = repl_command.split repl_commands = repl_command.split
...@@ -138,7 +141,7 @@ module Pod ...@@ -138,7 +141,7 @@ module Pod
arguments = repl_commands arguments = repl_commands
subcommand_class = Pod::Command::IPC.const_get(subcommand) subcommand_class = Pod::Command::IPC.const_get(subcommand)
subcommand_class.new(CLAide::ARGV.new(arguments)).run subcommand_class.new(CLAide::ARGV.new(arguments)).run
signal_ready signal_end_of_output
end end
end end
......
...@@ -3,6 +3,13 @@ require File.expand_path('../../../spec_helper', __FILE__) ...@@ -3,6 +3,13 @@ require File.expand_path('../../../spec_helper', __FILE__)
module Pod module Pod
describe Command::IPC do describe Command::IPC do
before do
Command::IPC::Spec.any_instance.stubs(:output_pipe).returns(UI)
Command::IPC::Podfile.any_instance.stubs(:output_pipe).returns(UI)
Command::IPC::List.any_instance.stubs(:output_pipe).returns(UI)
Command::IPC::Repl.any_instance.stubs(:output_pipe).returns(UI)
end
describe Command::IPC::Spec do describe Command::IPC::Spec do
it "converts a podspec to yaml and prints it to STDOUT" do it "converts a podspec to yaml and prints it to STDOUT" do
...@@ -69,7 +76,7 @@ module Pod ...@@ -69,7 +76,7 @@ module Pod
out.should.match /target_definitions:/ out.should.match /target_definitions:/
out.should.match /platform: ios/ out.should.match /platform: ios/
out.should.match /- SSZipArchive:/ out.should.match /- SSZipArchive:/
out.should.match />>> @LISTENING <<<$/ out.should.end_with?("\n\r")
end 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