dockershell

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func C

func C(args ...string) []string

C is an alias of []string which represents a command.

func Supported

func Supported() error

Supported checks if this pkg can run on the current system.

Types

type DefaultReporter

type DefaultReporter struct{}

DefaultReporter is the default implementation of Reporter.

func (DefaultReporter) Errorf

func (r DefaultReporter) Errorf(format string, v ...interface{})

Errorf prints the occurred error.

func (DefaultReporter) Logf

func (r DefaultReporter) Logf(format string, v ...interface{})

Errorf prints the information reported.

func (DefaultReporter) Stderr

func (r DefaultReporter) Stderr() io.Writer

Stdout provides the writer to stderr.

func (DefaultReporter) Stdout

func (r DefaultReporter) Stdout() io.Writer

Stdout provides the writer to stdout.

type Reporter

type Reporter interface {

	// Errorf is called when Shell encounters unrecoverable error.
	Errorf(format string, v ...interface{})

	// Logf is called to report some useful information (e.g. executing command) by Shell.
	Logf(format string, v ...interface{})

	// Stdout is used as a stdout destination of executing commands.
	Stdout() io.Writer

	// Stdout is used as a stderr destination of executing commands.
	Stderr() io.Writer
}

Reporter is used by Shell pkg to report logs and errors during commands execution.

type Shell

type Shell struct {
	*dexec.Exec
	// contains filtered or unexported fields
}

Shell provides provides means to execute commands inside a container, in a shellscript-like experience.

func New

func New(de *dexec.Exec, r Reporter) *Shell

When Shell encounters an unrecoverable error (e.g. failure of a command execution), this immediately calls Reporter.Errorf and don't execute the remaining (chained) commands. Err() method returns the last encountered error. Once Shell encounters an error, this is marked as "invalid" and doesn't accept any further command execution. For continuing further execution, call Refresh for aquiering a new instance of Shell.

Some useful information are also reported via Reporter.Logf during commands execution and command outputs to stdio are streamed into Reporter.Stdout and Reporter.Stderr.

If no Reporter is specified (i.e. nil is provided), DefaultReporter is used by default.

func (*Shell) Err

func (s *Shell) Err() error

Err returns an error encouterd at the last.

func (*Shell) ForEach

func (s *Shell) ForEach(args []string, f func(l string) bool) error

ForEach executes a command. For each line of stdout, the callback function is called until it returns false. Stderr is streamed to Reporter. The encountered erros are returned instead of using Reporter.

func (*Shell) Gox

func (s *Shell) Gox(args ...string) *Shell

Gox executes a command in an goroutine and doesn't wait for the command completion. Stdio is streamed to Reporter. When the command fails, different from X, the error is reported via Reporter.Logf and this Shell still *accepts* further command execution.

func (*Shell) IsInvalid

func (s *Shell) IsInvalid() bool

IsInvalid returns true when this Shell is marked as "invalid". For continuing further command execution, call Refresh for aquiering a new instance of Shell.

func (*Shell) O

func (s *Shell) O(args ...string) []byte

O executes a command and return the stdout. Stderr is streamed to Reporter. When the command fails, the error is reported via Reporter.Errorf and this Shell is marked as "invalid" (i.e. doesn't accept further command execution).

func (*Shell) OLog

func (s *Shell) OLog(args ...string) ([]byte, error)

OLog executes a command and return the stdout. Stdio is streamed to Reporter. When the command fails, different from O, the error is reported via Reporter.Logf and this Shell still *accepts* further command execution.

func (*Shell) Pipe

func (s *Shell) Pipe(out io.Writer, commands ...[]string) *Shell

Pipe executes passed commands sequentially and stdout of a command is piped into the next command's stdin. The stdout of the last command is streamed to the specified io.Writer. When a command fails, the error is reported via Reporter.Errorf and this Shell is marked as "invalid" (i.e. doesn't accept further command execution).

func (*Shell) R

func (s *Shell) R(args ...string) (stdout, stderr io.Reader, err error)

R executes a command. Stdio is returned as io.Reader. streamed to Reporter.

func (*Shell) Refresh

func (s *Shell) Refresh() *Shell

Refresh returns a new cloned instance of this Shell.

func (*Shell) Retry

func (s *Shell) Retry(num int, args ...string) *Shell

Retry executes a command repeatedly until it succeeds, up to num times. Stdio is streamed to Reporter. If all attemptions fail, the error is reported via Reporter.Errorf and this Shell is marked as "invalid" (i.e. doesn't accept further command execution).

func (*Shell) X

func (s *Shell) X(args ...string) *Shell

X executes a command. Stdio is streamed to Reporter. When the command fails, the error is reported via Reporter.Errorf and this Shell is marked as "invalid" (i.e. doesn't accept further command execution).

func (*Shell) XLog

func (s *Shell) XLog(args ...string) *Shell

XLog executes a command. Stdio is streamed to Reporter. When the command fails, different from X, the error is reported via Reporter.Logf and this Shell still *accepts* further command execution.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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