Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Commander ¶
type Commander interface {
// Line returns the "command line" to send to a shell (a string).
// The line can be computed from command instance internals.
Line() string
// SinkOut accepts shell's stdOut output for parsing.
// TODO: WriteCloser instead? Any advantage to offering a Close method?
SinkOut() io.Writer
// SinkErr accepts shell's stdErr output for parsing.
SinkErr() io.Writer
}
Commander encapsulates command line generation and parsing. The exact form of a command influences how it is parsed, making it convenient to encapsulate both in the same struct coverable with regression tests.
type Runner ¶
type Runner interface {
// Start starts the shell subprocess and confirms sentinel behavior.
// This method is synchronous.
// Errors:
// * The shell is already running because of a previous call to Start.
// * The shell cannot be found, fails to start or otherwise crashes.
// * The sentinels don't work in the allotted time.
// It should be okay to call Start again after Stop, or after an error.
// It's assumed that the implementation won't leak subprocesses.
Start(time.Duration) error
// RunIt runs the given Commander.
// This method is synchronous.
// This method returns nil when the command is known to be done (via
// sentinels) and the shell is ready to accept another Run call.
// Errors:
// * The shell isn't running (Start wasn't called, or the shell
// is in an error state).
// * The shell exits with any status code (including zero).
// * The timeout expires.
// * Run was already called (presumably by another thread) and has
// not completed.
// Any error means the shell is dead, and Run can no longer be called.
// A call to Start is required.
RunIt(Commander, time.Duration) error
// Stop tells the shell to exit.
// This method is synchronous.
// Errors:
// * The shell isn't running (Start wasn't called).
// * The shell exits with a status != 0.
// It should be okay to call Start again after Stop.
Stop(time.Duration) error
}
Runner manages a shell program. It has these states,
off (Start not called, or Stop called and finished, or error encountered), idle (Start called and finished, but not Run),
type Sentinel ¶
type Sentinel interface {
// Line returns the "command line" to send to a shell (a string).
// Example: echo "rumpelstiltskin"
Line() string
// Writer accepts output from the shell.
io.Writer
// Found can be called after a call to Write to
// see if the sentinel value was written.
// Example of expected output: rumpelstiltskin
Found() bool
}
Sentinel is simplified Commander with a Found metric.
Click to show internal directories.
Click to hide internal directories.