cmd

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package cmd describes command and command result interface and implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

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

func NewAnswer

func NewAnswer(question, answer string) Answer

func (Answer) GetExpr

func (m Answer) GetExpr() expr.Expr

func (Answer) Match

func (m Answer) Match(question []byte) ([]byte, error)

type Cmd

type Cmd interface {
	// GetCmdTimeout returns command timeout
	GetCmdTimeout() time.Duration
	// GetReadTimeout returns timeout between sequential reads
	GetReadTimeout() time.Duration
	// Value returns command value
	Value() []byte
	// GetExprCallback returns mapping of expressions and callbacks
	// to call if matched.
	GetExprCallback() ([]string, map[string]string)
	// QuestionHandler is called when question is matched.
	QuestionHandler(question []byte) ([]byte, error)
	// GetQuestionExprs returns list of possible questions.
	GetQuestionExprs() []expr.Expr
	// ErrorHandler is called when where is an error found in output.
	ErrorHandler(error) error
	// GetAgentForward returns whether SSH agent should be forwarded during execution.
	GetAgentForward() bool
}

Cmd is an interface for command.

func NewCmd

func NewCmd(command string, opts ...CmdOption) Cmd

func NewCmdList

func NewCmdList(commands []string, opts ...CmdOption) []Cmd

type CmdImpl

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

CmdImpl implements Cmd interface.

func (CmdImpl) ErrorHandler

func (m CmdImpl) ErrorHandler(err error) error

func (CmdImpl) GetAgentForward

func (m CmdImpl) GetAgentForward() bool

func (CmdImpl) GetCmdTimeout

func (m CmdImpl) GetCmdTimeout() time.Duration

func (CmdImpl) GetExprCallback

func (m CmdImpl) GetExprCallback() ([]string, map[string]string)

func (CmdImpl) GetQuestionExprs

func (m CmdImpl) GetQuestionExprs() []expr.Expr

func (CmdImpl) GetReadTimeout

func (m CmdImpl) GetReadTimeout() time.Duration

func (CmdImpl) QuestionHandler

func (m CmdImpl) QuestionHandler(question []byte) ([]byte, error)

func (CmdImpl) Value

func (m CmdImpl) Value() []byte

type CmdOption

type CmdOption func(*CmdImpl)

func WithAnswers

func WithAnswers(answers ...Answer) CmdOption

func WithCmdTimeout

func WithCmdTimeout(timeout time.Duration) CmdOption

func WithErrorIgnore

func WithErrorIgnore() CmdOption

func WithExprCallback

func WithExprCallback(exprCallbacks ...ExprCallback) CmdOption

func WithForwarding

func WithForwarding(forward bool) CmdOption

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) CmdOption

type CmdRes

type CmdRes interface {
	Output() []byte
	Error() []byte
	Status() int
	SetExtra(string, interface{})
	GetExtra(string) (interface{}, bool)
}

CmdRes is an interface for command result.

func NewCmdRes

func NewCmdRes(output []byte) CmdRes

func NewCmdResFull

func NewCmdResFull(output, err []byte, status int, extra map[string]interface{}) CmdRes

type ExprCallback

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

func NewExprCallback

func NewExprCallback(expr, write string) ExprCallback

type Res

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

func (*Res) Error

func (m *Res) Error() []byte

func (*Res) GetExtra

func (m *Res) GetExtra(key string) (interface{}, bool)

func (*Res) Output

func (m *Res) Output() []byte

func (*Res) SetExtra

func (m *Res) SetExtra(key string, value interface{})

func (*Res) Status

func (m *Res) Status() int

Jump to

Keyboard shortcuts

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