genericexec

package
v0.0.0-...-b5d9cbe Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package genericexec provides a common interface to execute local commands and remote commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd interface {
	// Run runs an external command synchronously.
	//
	// extraArgs is appended to the base arguments passed to the constructor
	// of Cmd. stdin specifies the data sent to the standard input of the
	// process. The standard output/error of the process are written to
	// stdout/stderr.
	Run(ctx context.Context, extraArgs []string, stdin io.Reader, stdout, stderr io.Writer) error

	// Interact starts an external command asynchronously.
	//
	// extraArgs is appended to the base arguments passed to the constructor
	// of Cmd. Returned Process can be used to interact with the new
	// subprocess.
	//
	// When ctx is canceled, the subprocess is killed by a signal, or
	// stdin of the subprocess is closed, depending on implementation.
	// Therefore Interact is safe to be used only with external commands
	// that exit on closing stdin.
	Interact(ctx context.Context, extraArgs []string) (Process, error)

	// DebugCommand returns a new command that runs the existing command under a
	// debugger waiting on port debugPort, if debugPort is non-zero.
	// It will also ensure that the command is runnable, such as by killing
	// the old debugger.
	DebugCommand(ctx context.Context, debugPort int) (Cmd, error)
}

Cmd is a common interface abstracting an external command to execute.

type ExecCmd

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

ExecCmd represents a local command to execute.

func CommandExec

func CommandExec(name string, baseArgs ...string) *ExecCmd

CommandExec constructs a new ExecCmd representing a local command to execute.

func (*ExecCmd) DebugCommand

func (c *ExecCmd) DebugCommand(ctx context.Context, debugPort int) (Cmd, error)

DebugCommand returns a version of this command that will run under the debugger.

func (*ExecCmd) Interact

func (c *ExecCmd) Interact(ctx context.Context, extraArgs []string) (p Process, retErr error)

Interact runs a local command asynchronously. See Cmd.Interact for details.

func (*ExecCmd) Run

func (c *ExecCmd) Run(ctx context.Context, extraArgs []string, stdin io.Reader, stdout, stderr io.Writer) error

Run runs a local command synchronously. See Cmd.Run for details.

type ExecProcess

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

ExecProcess represents a locally running process.

func (*ExecProcess) ProcessState

func (p *ExecProcess) ProcessState() *os.ProcessState

ProcessState returns the os.ProcessState object for the process..

func (*ExecProcess) Stderr

func (p *ExecProcess) Stderr() io.ReadCloser

Stderr returns stderr of the process.

func (*ExecProcess) Stdin

func (p *ExecProcess) Stdin() io.WriteCloser

Stdin returns stdin of the process.

func (*ExecProcess) Stdout

func (p *ExecProcess) Stdout() io.ReadCloser

Stdout returns stdout of the process.

func (*ExecProcess) Wait

func (p *ExecProcess) Wait(ctx context.Context) error

Wait waits for the process to exit. See Process.Wait for details.

type Process

type Process interface {
	// Stdin returns stdin of the process.
	Stdin() io.WriteCloser

	// Stdout returns stdout of the process.
	Stdout() io.ReadCloser

	// Stderr returns stderr of the process.
	Stderr() io.ReadCloser

	// Wait waits for the process to exit.
	//
	// Wait also releases resources associated to the process, so it must
	// be always called when you are done with it.
	//
	// Upon Wait finishes, io.ReadCloser returned by Stdout and Stderr
	// might be closed. This means that it is wrong to call Wait before
	// finishing to read necessary data from stdout/stderr.
	//
	// When ctx is canceled, the subprocess is killed by a signal, or
	// stdin of the subprocess is closed, depending on implementation.
	Wait(ctx context.Context) error
}

Process is a common interface abstracting a running external process.

type SSHCmd

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

SSHCmd represents a remote command to execute via SSH.

func CommandSSH

func CommandSSH(conn *ssh.Conn, name string, baseArgs ...string) *SSHCmd

CommandSSH constructs a new SSHCmd representing a remote command to execute via SSH.

func (*SSHCmd) DebugCommand

func (c *SSHCmd) DebugCommand(ctx context.Context, debugPort int) (Cmd, error)

DebugCommand returns a version of this command that will run under the debugger.

func (*SSHCmd) Interact

func (c *SSHCmd) Interact(ctx context.Context, extraArgs []string) (p Process, retErr error)

Interact runs a remote command asynchronously. See Cmd.Interact for details.

func (*SSHCmd) Run

func (c *SSHCmd) Run(ctx context.Context, extraArgs []string, stdin io.Reader, stdout, stderr io.Writer) error

Run runs a remote command synchronously. See Cmd.Run for details.

type SSHProcess

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

SSHProcess represents a remotely running process over SSH.

func (*SSHProcess) Stderr

func (p *SSHProcess) Stderr() io.ReadCloser

Stderr returns stderr of the process.

func (*SSHProcess) Stdin

func (p *SSHProcess) Stdin() io.WriteCloser

Stdin returns stdin of the process.

func (*SSHProcess) Stdout

func (p *SSHProcess) Stdout() io.ReadCloser

Stdout returns stdout of the process.

func (*SSHProcess) Wait

func (p *SSHProcess) Wait(ctx context.Context) error

Wait waits for the process to exit. See Process.Wait for details.

Jump to

Keyboard shortcuts

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