command

package
v1.4.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecRunner

type ExecRunner struct{}

ExecRunner runs commands using the os/exec package.

It implements the CommandRunner interface.

func (*ExecRunner) CombinedOutput

func (e *ExecRunner) CombinedOutput(cmd string) (string, error)

CombinedOutput runs the command in a bash shell and returns its combined standard output and standard error.

func (*ExecRunner) CombinedOutputTo

func (*ExecRunner) CombinedOutputTo(cmd string, out io.Writer) error

CombinedOutputTo runs the command and stores both command output and error to out.

func (*ExecRunner) Copy

Copy copies a file and its permissions

func (*ExecRunner) Remove

func (e *ExecRunner) Remove(f assets.CopyableFile) error

Remove removes a file

func (*ExecRunner) Run

func (*ExecRunner) Run(cmd string) error

Run starts the specified command in a bash shell and waits for it to complete.

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) CombinedOutput

func (f *FakeCommandRunner) CombinedOutput(cmd string) (string, error)

CombinedOutput returns the set output for a given command text.

func (*FakeCommandRunner) CombinedOutputTo

func (f *FakeCommandRunner) CombinedOutputTo(cmd string, out io.Writer) error

CombinedOutputTo runs the command and stores both command output and error to out.

func (*FakeCommandRunner) Copy

Copy adds the filename, file contents key value pair 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) Remove

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

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

func (*FakeCommandRunner) Run

func (f *FakeCommandRunner) Run(cmd string) error

Run returns nil if output has been set for the given command text.

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

type Runner

type Runner interface {
	// Run starts the specified command and waits for it to complete.
	Run(cmd string) error

	// CombinedOutputTo runs the command and stores both command
	// output and error to out. A typical usage is:
	//
	//          var b bytes.Buffer
	//          CombinedOutput(cmd, &b)
	//          fmt.Println(b.Bytes())
	//
	// Or, you can set out to os.Stdout, the command output and
	// error would show on your terminal immediately before you
	// cmd exit. This is useful for a long run command such as
	// continuously print running logs.
	CombinedOutputTo(cmd string, out io.Writer) error

	// CombinedOutput runs the command and returns its combined standard
	// output and standard error.
	CombinedOutput(cmd string) (string, error)

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

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

Runner represents an interface to run commands.

type SSHRunner

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

SSHRunner runs commands through SSH.

It implements the CommandRunner interface.

func NewSSHRunner

func NewSSHRunner(c *ssh.Client) *SSHRunner

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

func (*SSHRunner) CombinedOutput

func (s *SSHRunner) CombinedOutput(cmd string) (string, error)

CombinedOutput runs the command on the remote and returns its combined standard output and standard error.

func (*SSHRunner) CombinedOutputTo

func (s *SSHRunner) CombinedOutputTo(cmd string, w io.Writer) error

CombinedOutputTo runs the command and stores both command output and error to out.

func (*SSHRunner) Copy

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

Copy copies a file to the remote over SSH.

func (*SSHRunner) Remove

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

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

func (*SSHRunner) Run

func (s *SSHRunner) Run(cmd string) error

Run starts a command on the remote and waits for it to return.

Jump to

Keyboard shortcuts

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