expect

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2022 License: MIT Imports: 10 Imported by: 3

README

simple expect in golang

Usage

  1. Call expect.Popen/PopenPTY to execute command

    See sample.

  2. Call expect.Spawn/SpawnPTY to implement TCL-like expect

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotFound = fmt.Errorf("not matched")
	TimedOut = fmt.Errorf("timed out")
)

Functions

This section is empty.

Types

type Action added in v0.2.0

type Action uint8
const (
	Continue Action = iota
	Break
)

type Case

type Case struct {
	Exp         *regexp.Regexp
	SkipTill    byte
	MatchedOnly bool
	ExpMatched  FnMatched
}

type Cmd added in v0.1.2

type Cmd struct {
	Exit chan struct{}
	// contains filtered or unexported fields
}

func Popen

func Popen(ioHandlers IOHandlers, cmdPath string, arg ...string) (cmd *Cmd, err error)

func PopenPTY

func PopenPTY(ioHandlers IOHandlers, cmdPath string, arg ...string) (cmd *Cmd, err error)

func (*Cmd) Close added in v0.1.2

func (cmd *Cmd) Close()

func (*Cmd) Wait added in v0.1.2

func (cmd *Cmd) Wait() (exitCode int, err error)

type Expect

type Expect struct {
	// contains filtered or unexported fields
}

func Spawn

func Spawn(prog string, arg ...string) (e *Expect, err error)

func SpawnPTY

func SpawnPTY(prog string, arg ...string) (e *Expect, err error)

func SpawnPTYWithEnvs added in v0.2.2

func SpawnPTYWithEnvs(envs map[string]string, prog string, arg ...string) (e *Expect, err error)

func SpawnWithEnvs added in v0.2.2

func SpawnWithEnvs(envs map[string]string, prog string, arg ...string) (e *Expect, err error)

func (*Expect) Close

func (e *Expect) Close()

func (*Expect) Expect

func (e *Expect) Expect(expr string, expMathed ...FnMatched) ([]byte, error)

func (*Expect) ExpectCases

func (e *Expect) ExpectCases(cases ...*Case) (idx int, m []byte, err error)

func (*Expect) ExpectRegexp

func (e *Expect) ExpectRegexp(re *regexp.Regexp, expMathed ...FnMatched) ([]byte, error)

func (*Expect) GetEnvs added in v0.2.2

func (e *Expect) GetEnvs() map[string]string

func (*Expect) HandleStderr

func (e *Expect) HandleStderr(stderr io.ReadCloser)

func (*Expect) HandleStdin

func (e *Expect) HandleStdin(stdin io.WriteCloser)

func (*Expect) HandleStdout

func (e *Expect) HandleStdout(stdout io.ReadCloser)

func (*Expect) RemoveColor added in v0.2.1

func (e *Expect) RemoveColor()

func (*Expect) Send

func (e *Expect) Send(s string)

func (*Expect) SetNotMatchedHandler added in v0.2.2

func (e *Expect) SetNotMatchedHandler(notMatched FnNotMatched)

func (*Expect) SetTimeout

func (e *Expect) SetTimeout(d time.Duration)

func (*Expect) Wait

func (e *Expect) Wait() (exitCode int, err error)

type FnMatched added in v0.2.0

type FnMatched func(m []byte) Action

type FnNotMatched added in v0.2.2

type FnNotMatched func(m []byte) (skipN int)

type IOHandlers

type IOHandlers interface {
	HandleStdin(io.WriteCloser)
	HandleStdout(io.ReadCloser)
	HandleStderr(io.ReadCloser)
	GetEnvs() map[string]string
}

Jump to

Keyboard shortcuts

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