Documentation
¶
Index ¶
- func EnsureLineTermination(cmd string) string
- type Command
- type History
- type Listener
- type Option
- func AsPipeline() Option
- func WithEnvironment(env map[string]string) Option
- func WithFlashIntervalMs(ts int) Option
- func WithHistory(history *History) Option
- func WithListener(listener Listener) Option
- func WithPath(aPath string) Option
- func WithRunner(runner Runner) Option
- func WithShell(shell string) Option
- func WithShellPrompt(shellPrompt string) Option
- func WithSystemPaths(paths []string) Option
- func WithTerminators(terminators []string) Option
- func WithTimeout(timeoutMs int) Option
- type Options
- type Pipeline
- func (p *Pipeline) Close() (err error)
- func (p *Pipeline) Drain(ctx context.Context, opts ...Option)
- func (p *Pipeline) Err() error
- func (p *Pipeline) FormatCmd(cmd string) string
- func (p *Pipeline) Listen(ctx context.Context, opts ...Option) error
- func (p *Pipeline) Read(ctx context.Context, opts ...Option) (output string, has bool, code int, err error)
- func (p *Pipeline) Running() bool
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureLineTermination ¶ added in v0.2.0
Types ¶
type Listener ¶
Listener represent command listener (it will send stdout fragments as thier being available on stdout)
type Option ¶
type Option func(*Options)
Option represents runner option
func AsPipeline ¶ added in v0.2.0
func AsPipeline() Option
func WithEnvironment ¶
WithEnvironment creates with environment option
func WithFlashIntervalMs ¶
WithFlashIntervalMs creates with flash time option
func WithHistory ¶
WithHistory creates with history option
func WithListener ¶
WithListener creates with listener option
func WithShellPrompt ¶
WithShellPrompt creates with shell prompt option
func WithSystemPaths ¶
WithSystemPaths creates with listener option
func WithTerminators ¶
WithTerminators creates with terminators option
type Options ¶
type Options struct {
Runner Runner
Shell string
Term string
Cols int
Rows int
Path string
Env map[string]string
SystemPaths []string
History *History
// contains filtered or unexported fields
}
Options represents runner options
func (*Options) AsPipeline ¶ added in v0.2.0
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline represents a command pipeline
func NewPipeline ¶
func NewPipeline(ctx context.Context, in io.WriteCloser, stdout io.Reader, stderr io.Reader, options *Options) (*Pipeline, error)
NewPipeline creates a new pipeline
func (*Pipeline) FormatCmd ¶
FormatCmd formats a command that is sent to an interactive shell via stdin.
Key guarantees:
- Always append a "status:" marker so the runner can detect completion and capture the exit code.
- Shield the shell's stdin from the user command by grouping and redirecting that group's stdin to /dev/null. This prevents commands that read from stdin from consuming the subsequently appended status marker. Explicit stdin redirections inside the user command still take precedence.
- Attempt to enable 'pipefail' (if supported) inside the group so pipelines report a non-zero status when any segment fails. On shells without pipefail, this attempt is silenced and the status falls back to that of the last command in the pipeline (standard POSIX behavior).
Final layout:
{ set -o pipefail 2>/dev/null; <user_command>; } </dev/null
status=$?; echo 'status:'$status
Using a group redirection avoids brittle parsing (quotes, pipes, heredocs) and reliably shields the shell stdin across a wide range of inputs.
type Runner ¶
type Runner interface {
//Run runs supplied command
Run(ctx context.Context, command string, options ...Option) (string, int, error)
//Sends data to stdin
Send(ctx context.Context, data []byte) (int, error)
//PID returns process id
PID() int
//Close closes runner
Close() error
}
Runner represents a command runner