Documentation ¶
Overview ¶
Package executor provides an interface for the executor as well as a local and remote implementation. The executor is used to run commands on the local machine or on a remote machine.
Index ¶
- type Connector
- type DeleteOpts
- type Dry
- func (ex *Dry) Close() error
- func (ex *Dry) Delete(_ context.Context, remoteFile string, opts *DeleteOpts) (err error)
- func (ex *Dry) Download(_ context.Context, remote, local string, opts *UpDownOpts) (err error)
- func (ex *Dry) Run(_ context.Context, cmd string, _ *RunOpts) (out []string, err error)
- func (ex *Dry) Sync(_ context.Context, localDir, remoteDir string, opts *SyncOpts) ([]string, error)
- func (ex *Dry) Upload(_ context.Context, local, remote string, opts *UpDownOpts) (err error)
- type Interface
- type Local
- func (l *Local) Close() error
- func (l *Local) Delete(ctx context.Context, remoteFile string, opts *DeleteOpts) (err error)
- func (l *Local) Download(_ context.Context, src, dst string, opts *UpDownOpts) (err error)
- func (l *Local) Run(ctx context.Context, cmd string, _ *RunOpts) (out []string, err error)
- func (l *Local) Sync(ctx context.Context, src, dst string, opts *SyncOpts) ([]string, error)
- func (l *Local) Upload(_ context.Context, src, dst string, opts *UpDownOpts) (err error)
- type LogWriter
- type Logs
- type Remote
- func (ex *Remote) Close() error
- func (ex *Remote) Delete(ctx context.Context, remoteFile string, opts *DeleteOpts) (err error)
- func (ex *Remote) Download(ctx context.Context, remote, local string, opts *UpDownOpts) (err error)
- func (ex *Remote) Run(ctx context.Context, cmd string, _ *RunOpts) (out []string, err error)
- func (ex *Remote) Sync(ctx context.Context, localDir, remoteDir string, opts *SyncOpts) ([]string, error)
- func (ex *Remote) Upload(ctx context.Context, local, remote string, opts *UpDownOpts) (err error)
- type RunOpts
- type SyncOpts
- type UpDownOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector provides factory methods to create Remote executor. Each executor is connected to a single SSH hostAddr.
func NewConnector ¶
NewConnector creates a new Connector for a given user and private key.
func (*Connector) Connect ¶
Connect connects to a remote hostAddr and returns a remote executer, caller must close.
func (*Connector) WithAgentForwarding ¶ added in v1.15.0
WithAgentForwarding enables ssh agent forwarding.
type DeleteOpts ¶ added in v1.5.0
type DeleteOpts struct { Recursive bool // delete directories recursively Exclude []string // exclude files matching the given patterns }
DeleteOpts is a struct for delete options.
type Dry ¶
type Dry struct {
// contains filtered or unexported fields
}
Dry is an executor for dry run, just prints commands and files to be copied, synced, deleted. Useful for debugging and testing, doesn't actually execute anything.
type Interface ¶
type Interface interface { Run(ctx context.Context, c string, opts *RunOpts) (out []string, err error) Upload(ctx context.Context, local, remote string, opts *UpDownOpts) (err error) Download(ctx context.Context, remote, local string, opts *UpDownOpts) (err error) Sync(ctx context.Context, localDir, remoteDir string, opts *SyncOpts) ([]string, error) Delete(ctx context.Context, remoteFile string, opts *DeleteOpts) (err error) Close() error }
Interface is an interface for the executor. Implemented by Remote, Local and Dry structs.
type Local ¶
type Local struct {
// contains filtered or unexported fields
}
Local is a runner for local execution. Similar to remote, but without ssh, just exec on localhost and local copy/delete/sync
type LogWriter ¶ added in v1.11.0
type LogWriter interface { io.Writer Printf(format string, v ...any) WithHost(hostAddr, hostName string) LogWriter WithWriter(wr io.Writer) LogWriter }
LogWriter is an interface for writing logs. Some implementations support colorization and secrets masking.
type Logs ¶ added in v1.11.0
type Logs struct { Info LogWriter Out LogWriter Err LogWriter // contains filtered or unexported fields }
Logs is a struct that contains two LogWriters, one for stdout and one for stderr.
func MakeLogs ¶ added in v1.11.0
MakeLogs creates a new set of loggers for stdout and stderr and logger for the main info. If verbose is true, the stdout and stderr logger will be colorized. infoLog is always colorized and used to log the main info, like the command that is being executed.
func (Logs) WithHost ¶ added in v1.11.0
WithHost creates a new Logs with the given hostAddr name for each LogWriter.
func (Logs) WithSecrets ¶ added in v1.11.0
WithSecrets creates a new Logs with the given secrets.
type Remote ¶
type Remote struct {
// contains filtered or unexported fields
}
Remote executes commands on remote server, via ssh. Not thread-safe.
func (*Remote) Delete ¶
Delete file on remote server. Recursively if recursive is true. if a file or directory does not exist, returns nil, i.e. no error.
type RunOpts ¶ added in v1.5.0
type RunOpts struct {
Verbose bool // print more info to primary stdout
}
RunOpts is a struct for run options.
type SyncOpts ¶ added in v1.5.0
type SyncOpts struct { Delete bool // delete extra files on remote Exclude []string // exclude files matching the given patterns Checksum bool // compare checksums of local and remote files, default is size and modtime Force bool // overwrite existing files on remote }
SyncOpts is a struct for sync options.
type UpDownOpts ¶ added in v1.5.0
type UpDownOpts struct { Mkdir bool // create remote directory if it does not exist Checksum bool // compare checksums of local and remote files, default is size and modtime Force bool // overwrite existing files on remote Exclude []string // exclude files matching the given patterns }
UpDownOpts is a struct for upload and download options.