command

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPrefix notes an error
	ErrPrefix = "! "

	// OutPrefix notes output
	OutPrefix = "> "
)

Functions

This section is empty.

Types

type FakeCommandRunner

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

FakeCommandRunner mocks command output without running the Commands

It implements the CommandRunner interface and is used for testing.

func NewFakeCommandRunner

func NewFakeCommandRunner() *FakeCommandRunner

NewFakeCommandRunner returns a new FakeCommandRunner

The expected output of commands should be set with SetCommandToOutput

func (*FakeCommandRunner) Copy

Copy adds the filename, file contents key value pair to the stored map.

func (*FakeCommandRunner) CopyFrom added in v1.23.0

func (f *FakeCommandRunner) CopyFrom(file assets.CopyableFile) error

CopyFrom copy content from file to the stored map.

func (*FakeCommandRunner) DumpMaps

func (f *FakeCommandRunner) DumpMaps(w io.Writer)

DumpMaps prints out the list of stored commands and stored filenames.

func (*FakeCommandRunner) GetFileToContents

func (f *FakeCommandRunner) GetFileToContents(filename string) (string, error)

GetFileToContents stores the file to contents map for the FakeCommandRunner

func (*FakeCommandRunner) ReadableFile added in v1.25.0

func (f *FakeCommandRunner) ReadableFile(_ string) (assets.ReadableFile, error)

ReadableFile implements interface (without implementation)

func (*FakeCommandRunner) Remove

func (f *FakeCommandRunner) Remove(file assets.CopyableFile) error

Remove removes the filename, file contents key value pair from the stored map

func (*FakeCommandRunner) RunCmd added in v1.5.2

func (f *FakeCommandRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error)

RunCmd implements the Command Runner interface to run a exec.Cmd object

func (*FakeCommandRunner) SetCommandToOutput

func (f *FakeCommandRunner) SetCommandToOutput(cmdToOutput map[string]string)

SetCommandToOutput stores the file to contents map for the FakeCommandRunner

func (*FakeCommandRunner) SetFileToContents

func (f *FakeCommandRunner) SetFileToContents(fileToContents map[string]string)

SetFileToContents stores the file to contents map for the FakeCommandRunner

func (*FakeCommandRunner) StartCmd added in v1.16.0

func (f *FakeCommandRunner) StartCmd(cmd *exec.Cmd) (*StartedCmd, error)

StartCmd implements the Command Runner interface to start a exec.Cmd object

func (*FakeCommandRunner) WaitCmd added in v1.16.0

func (f *FakeCommandRunner) WaitCmd(sc *StartedCmd) (*RunResult, error)

WaitCmd implements the Command Runner interface to wait until a started exec.Cmd object finishes

type RunResult added in v1.5.2

type RunResult struct {
	Stdout   bytes.Buffer
	Stderr   bytes.Buffer
	ExitCode int
	Args     []string // the args that was passed to Runner
}

RunResult holds the results of a Runner

func (RunResult) Command added in v1.5.2

func (rr RunResult) Command() string

Command returns a human readable command string that does not induce eye fatigue

func (RunResult) Output added in v1.5.2

func (rr RunResult) Output() string

Output returns human-readable output for an execution result

type Runner

type Runner interface {
	// RunCmd runs a cmd of exec.Cmd type. allowing user to set cmd.Stdin, cmd.Stdout,...
	// not all implementors are guaranteed to handle all the properties of cmd.
	RunCmd(cmd *exec.Cmd) (*RunResult, error)

	// StartCmd starts a cmd of exec.Cmd type.
	// This func in non-blocking, use WaitCmd to block until complete.
	// Not all implementors are guaranteed to handle all the properties of cmd.
	StartCmd(cmd *exec.Cmd) (*StartedCmd, error)

	// WaitCmd will prevent further execution until the started command has completed.
	WaitCmd(startedCmd *StartedCmd) (*RunResult, error)

	// Copy is a convenience method that runs a command to copy a file
	Copy(assets.CopyableFile) error

	// CopyFrom is a convenience method that runs a command to copy a file back
	CopyFrom(assets.CopyableFile) error

	// Remove is a convenience method that runs a command to remove a file
	Remove(assets.CopyableFile) error

	// ReadableFile open a remote file for reading
	ReadableFile(sourcePath string) (assets.ReadableFile, error)
}

Runner represents an interface to run commands.

func NewExecRunner added in v1.7.0

func NewExecRunner(sudo bool) Runner

NewExecRunner returns a kicRunner implementor of runner which runs cmds inside a container

func NewKICRunner added in v1.7.0

func NewKICRunner(containerNameOrID string, oci string) Runner

NewKICRunner returns a kicRunner implementor of runner which runs cmds inside a container

type SSHRunner

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

SSHRunner runs commands through SSH.

It implements the CommandRunner interface.

func NewSSHRunner

func NewSSHRunner(d drivers.Driver) *SSHRunner

NewSSHRunner returns a new SSHRunner that will run commands through the ssh.Client provided.

func (*SSHRunner) Copy

func (s *SSHRunner) Copy(f assets.CopyableFile) error

Copy copies a file to the remote over SSH.

func (*SSHRunner) CopyFrom added in v1.23.0

func (s *SSHRunner) CopyFrom(f assets.CopyableFile) error

CopyFrom copies a file from the remote over SSH.

func (*SSHRunner) ReadableFile added in v1.25.0

func (s *SSHRunner) ReadableFile(sourcePath string) (assets.ReadableFile, error)

ReadableFile returns assets.ReadableFile for the sourcePath (via `stat` command)

func (*SSHRunner) Remove

func (s *SSHRunner) Remove(f assets.CopyableFile) error

Remove runs a command to delete a file on the remote.

func (*SSHRunner) RunCmd added in v1.5.2

func (s *SSHRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error)

RunCmd implements the Command Runner interface to run a exec.Cmd object

func (*SSHRunner) StartCmd added in v1.16.0

func (s *SSHRunner) StartCmd(cmd *exec.Cmd) (*StartedCmd, error)

StartCmd implements the Command Runner interface to start a exec.Cmd object

func (*SSHRunner) WaitCmd added in v1.16.0

func (s *SSHRunner) WaitCmd(sc *StartedCmd) (*RunResult, error)

WaitCmd implements the Command Runner interface to wait until a started exec.Cmd object finishes

type StartedCmd added in v1.16.0

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

StartedCmd holds the contents of a started command

Jump to

Keyboard shortcuts

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