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