Module: Amberletters

Defined in:
lib/amberletters.rb,
lib/amberletters/version.rb

Overview

A better expect.rb

Started from github.com/avdi/Amberletters and then tweeked.

Implementation note: because of the way PTY is implemented in Ruby, it is possible when executing a quick non-interactive command for PTY::ChildExited to be raised before ever getting input/output handles to the child process. Without an output handle, it’s not possible to read any output the process produced. This is obviously undesirable, especially since when a command is unexpectedly quick and noninteractive it’s usually because there was an error and you really want to be able to see what the problem was.

Amberletters’ solution to this problem is to wrap every command in a short script. The script executes the passed command and on termination, outputs an easily recognizable marker string. Then it waits for acknowledgment (a newline) before exiting. When Amberletters sees the marker string in the output, it automatically performs the acknowledgement and allows the child process to finish. By forcing the child process to wait for acknowledgement, we guarantee that the child will never exit before we have a chance to look at the output.

Defined Under Namespace

Classes: BytesTrigger, ExitTrigger, OutputTrigger, Process, TimeoutTrigger, TranscriptHistoryBuffer, Trigger, UnsatisfiedTrigger

Constant Summary collapse

LogicError =
Class.new(::Exception)
SystemError =
Class.new(RuntimeError)
TimeoutError =
Class.new(SystemError)
ClientError =
Class.new(RuntimeError)
StateError =
Class.new(ClientError)
VERSION =
"0.1.0"