reel

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2021 License: GPL-2.0 Imports: 5 Imported by: 0

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

View Source
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

func NewReel(expecter *expect.Expecter, args []string, errorChannel <-chan error) (*Reel, error)

NewReel create a new `Reel` instance for interacting with a target subprocess. The command line for the target is specified by the args parameter.

func (*Reel) Run

func (r *Reel) Run(handler Handler) error

Run the target subprocess to completion. The first step to take is supplied by handler. Consequent steps are determined by handler in response to events. Return on first error, or when there is no next step to execute.

func (*Reel) Step

func (r *Reel) Step(step *Step, handler Handler) error

Step performs `step`, then, in response to events, consequent steps fed by `handler`. Return on first error, or when there is no next step to perform.

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.

type StepFunc

type StepFunc func(Handler) *Step

StepFunc provides a wrapper around a generic Handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL