Documentation
¶
Overview ¶
Package reel runs a target subprocess with programmatic control over interaction with it. Programmatic control uses a Read-Execute-Expect-Loop ("REEL") pattern.
Index ¶
Constants ¶
const ( // CtrlC is the constant representing SIGINT. CtrlC = "\003" // ^C )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface {
// ReelFirst returns the first step to perform.
ReelFirst() *Step
// ReelMatch informs of a match event, returning the next step to perform. ReelMatch takes three arguments:
// `pattern` represents the regular expression pattern which was matched.
// `before` contains all output preceding `match`.
// `match` is the text matched by `pattern`.
ReelMatch(pattern string, before string, match string) *Step
// ReelTimeout informs of a timeout event, returning the next step to perform.
ReelTimeout() *Step
// ReelEOF informs of the eof event.
ReelEOF()
}
A Handler implements desired programmatic control.
type Reel ¶
type Reel struct {
Err error
// contains filtered or unexported fields
}
A Reel instance allows interaction with a target subprocess.
func NewReel ¶
NewReel create a new `Reel` instance for interacting with a target subprocess. The command line for the target is specified by the args parameter.
type Step ¶
type Step struct {
// Execute is a Unix command to execute using the underlying subprocess.
Execute string `json:"execute,omitempty" yaml:"execute,omitempty"`
// Expect is an array of expected text regular expressions. The first expectation results in a match.
Expect []string `json:"expect,omitempty" yaml:"expect,omitempty"`
// Timeout is the timeout for the Step. A positive Timeout prevents blocking forever.
Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}
Step is an instruction for a single REEL pass. To process a step, first send the `Execute` string to the target subprocess (if supplied). Block until the subprocess output to stdout matches one of the regular expressions in `Expect` (if any supplied). A positive integer `Timeout` prevents blocking forever.