cli

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = SessionConfig{
	// contains filtered or unexported fields
}
View Source
var DefaultTransportConfig = TransportConfig{}

Functions

This section is empty.

Types

type FactoryImpl

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

func (FactoryImpl) NewSession

func (f FactoryImpl) NewSession(ctx context.Context, sshcfg *ssh.ClientConfig, target string,
	opts ...SessionOption,
) (s Session, err error)

type SSHTransport

type SSHTransport interface {
	io.WriteCloser
	io.Reader
}

func NewSSHTransport

func NewSSHTransport(ctx context.Context, sshcfg *ssh.ClientConfig, cfg *TransportConfig, target string) (SSHTransport, error)

type SendConfig

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

SendConfig defines properties controlling Send behaviour.

type SendOption

type SendOption func(*SendConfig)

SendOption implements options for configuring Send behaviour.

func NoNewline

func NoNewline() SendOption

NoNewline suppresses the newline that is by default appended to the Send string.

func NoWait

func NoWait() SendOption

NoWait indicates the Send should not wait for a response.

func ResetPrompt

func ResetPrompt() SendOption

ResetPrompt resets the current session prompt to the last unterminated line of response.

func WaitFor

func WaitFor(sentinel string) SendOption

WaitFor defines the string that indicates the end of the response to the send. Defaults to the current prompt.

type Session

type Session interface {
	// Send writes the supplied value to the server and returns the response.
	// The behaviour can be modified by opts - see SendOption variants below.
	Send(value string, opts ...SendOption) (string, error)
	io.Closer
}

Session defines the API exposed by an SSH client.

type SessionConfig

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

SessionConfig defines properties controlling session behaviour.

type SessionFactory

type SessionFactory interface {
	NewSession(ctx context.Context, sshcfg *ssh.ClientConfig, target string, opts ...SessionOption) (s Session, err error)
}

func NewSessionFactory

func NewSessionFactory(cfg *SessionConfig) SessionFactory

type SessionImpl

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

func NewCliSession

func NewCliSession(ctx context.Context, tport SSHTransport, cfg *SessionConfig) (s *SessionImpl, err error)

NewCliSession establishes a client connection to a cli session running on the server associated with the supplied transport.

func (*SessionImpl) Close

func (s *SessionImpl) Close() error

func (*SessionImpl) Send

func (s *SessionImpl) Send(output string, opts ...SendOption) (string, error)

type SessionOption

type SessionOption func(*SessionConfig)

SessionOption implements options for configuring session behaviour.

func WithCommands

func WithCommands(cmds ...string) SessionOption

WithCommand defines initialisation commands to be executed after a session has been established.

func WithPrompt

func WithPrompt(pattern string) SessionOption

WithPrompt overrides the automatic prompt detection that a new client session applies to determine the cli prompt that is used to detect the end of a server response. A non-empty pattern value defines a regular expression that will be used to detect the cli prompt. An empty pattern indicates the the WaitFor option when calling Send.

func WithTimeout

func WithTimeout(timeout time.Duration) SessionOption

WithTimeout defines the length of time to wait without receiving any input that is used to determine that the server has completed a response. Typically, only used when auto-detecting the cli prompt.

type TransportConfig

type TransportConfig struct{}

Jump to

Keyboard shortcuts

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