shellz

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package shellz provides various utilities for running commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RestoreDefaultExecutor

func RestoreDefaultExecutor()

RestoreDefaultExecutor restores the default value of DefaultExecutor.

Types

type Command

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

Command describes a command.

func NewCommand

func NewCommand(cmd string, params ...string) *Command

NewCommand creates a new *Command.

func (*Command) AddParams

func (c *Command) AddParams(params ...string) *Command

AddParams adds the given params.

func (*Command) AddParamsIfTrue

func (c *Command) AddParamsIfTrue(cond bool, params ...string) *Command

AddParamsIfTrue adds the given params if the condition is true.

func (*Command) CombinedOutput

func (c *Command) CombinedOutput() ([]byte, error)

CombinedOutput runs the command and returns a buffer containing the resulting combined standard output and error.

func (*Command) CombinedOutputString

func (c *Command) CombinedOutputString() (string, error)

CombinedOutputString is like *Command.CombinedOutput but returns a string.

func (*Command) Exec

func (c *Command) Exec() error

Exec the command (i.e. replace the current process).

func (*Command) GetDir

func (c *Command) GetDir() string

GetDir returns the current working directory.

func (*Command) GetEcho

func (c *Command) GetEcho() *bool

GetEcho returns the current echo configuration.

func (*Command) GetEnv

func (c *Command) GetEnv() map[string]string

GetEnv returns the current environment variables.

func (*Command) GetIn

func (c *Command) GetIn() io.Reader

GetIn returns the current input.

func (*Command) GetParams

func (c *Command) GetParams() []string

GetParams returns the current params.

func (*Command) Lines

func (c *Command) Lines(lineFunc func(string)) error

Lines runs the command and calls "lineFunc" with each line of output.

func (*Command) MergeEnv

func (c *Command) MergeEnv(env map[string]string) *Command

MergeEnv sets all the environment variables.

func (*Command) MustCombinedOutput

func (c *Command) MustCombinedOutput() []byte

MustCombinedOutput is like *Command.CombinedOutput but panics on error.

func (*Command) MustCombinedOutputString

func (c *Command) MustCombinedOutputString() string

MustCombinedOutputString is like *Command.CombinedOutputString but panics on error.

func (*Command) MustExec

func (c *Command) MustExec()

MustExec is like *Command.Exec but panics on error.

func (*Command) MustLines

func (c *Command) MustLines(lineFunc func(string))

MustLines is like *Command.Lines but panics on error.

func (*Command) MustOutput

func (c *Command) MustOutput(echoStderr bool) []byte

MustOutput is like *Command.Output but panics on error.

func (*Command) MustOutputString

func (c *Command) MustOutputString(echoStderr bool) string

MustOutputString is like *Command.OutputString but panics on error.

func (*Command) MustRun

func (c *Command) MustRun()

MustRun is like *Command.Run but panics on error.

func (*Command) Output

func (c *Command) Output(echoStderr bool) ([]byte, error)

Output runs the command and returns a buffer containing the resulting standard output. Standard error is not redirected.

func (*Command) OutputString

func (c *Command) OutputString(echoStderr bool) (string, error)

OutputString is like *Command.Output but returns a string.

func (*Command) Run

func (c *Command) Run() error

Run runs the command.

func (*Command) SetDir

func (c *Command) SetDir(dir string) *Command

SetDir sets the working directory.

func (*Command) SetEcho

func (c *Command) SetEcho(echo bool) *Command

SetEcho configures echo.

func (*Command) SetEnv

func (c *Command) SetEnv(k, v string) *Command

SetEnv sets an environment variable.

func (*Command) SetExecutor

func (c *Command) SetExecutor(executor Executor) *Command

SetExecutor sets the Executor for the command.

func (*Command) SetIn

func (c *Command) SetIn(in io.Reader) *Command

SetIn sets the input.

type ExecutionError

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

ExecutionError describes an error.

func NewExecutionError

func NewExecutionError(err error, c *Command) *ExecutionError

NewExecutionError initializes a new *ExecutionError.

func (*ExecutionError) Error

func (e *ExecutionError) Error() string

Error implements the error interface.

func (*ExecutionError) GetCapturedStderr

func (e *ExecutionError) GetCapturedStderr() string

GetCapturedStderr returns the originating captured standard error (if available).

func (*ExecutionError) GetCommand

func (e *ExecutionError) GetCommand() string

GetCommand returns the originating command.

func (*ExecutionError) GetDir

func (e *ExecutionError) GetDir() string

GetDir returns the originating dir.

func (*ExecutionError) GetEnv

func (e *ExecutionError) GetEnv() map[string]string

GetEnv returns the originating env.

func (*ExecutionError) GetExitCode

func (e *ExecutionError) GetExitCode() int

GetExitCode returns the originating exit code.

func (*ExecutionError) GetParams

func (e *ExecutionError) GetParams() []string

GetParams returns the originating params.

func (*ExecutionError) Unwrap

func (e *ExecutionError) Unwrap() error

Unwrap implements the errorz.UnwrapSingle interface.

type Executor

type Executor interface {
	ExecCmdCombinedOutput(c *Command, cmd *exec.Cmd) ([]byte, error)
	ExecCmdOutput(c *Command, cmd *exec.Cmd) ([]byte, error)
	ExecCmdRun(c *Command, cmd *exec.Cmd) error
	ExecCmdStart(c *Command, cmd *exec.Cmd) error
	ExecCmdWait(c *Command, cmd *exec.Cmd) error
	ExecLookPath(c *Command, file string) (string, error)
	OSChdir(c *Command, dir string) error
	SyscallExec(c *Command, argv0 string, argv []string, envv []string) error
}

Executor implements the OS-level operations related to a command.

var (
	DefaultExecutor Executor = defaultExecutor
)

DefaultExecutor is the default Executor for commands.

type RealExecutor

type RealExecutor struct {
}

RealExecutor implements the Executor interface and actually runs commands on the host.

func (*RealExecutor) ExecCmdCombinedOutput

func (e *RealExecutor) ExecCmdCombinedOutput(_ *Command, cmd *exec.Cmd) ([]byte, error)

ExecCmdCombinedOutput implements the Executor interface.

func (*RealExecutor) ExecCmdOutput

func (e *RealExecutor) ExecCmdOutput(_ *Command, cmd *exec.Cmd) ([]byte, error)

ExecCmdOutput implements the Executor interface.

func (*RealExecutor) ExecCmdRun

func (e *RealExecutor) ExecCmdRun(_ *Command, cmd *exec.Cmd) error

ExecCmdRun implements the Executor interface.

func (*RealExecutor) ExecCmdStart

func (e *RealExecutor) ExecCmdStart(_ *Command, cmd *exec.Cmd) error

ExecCmdStart implements the Executor interface.

func (*RealExecutor) ExecCmdWait

func (e *RealExecutor) ExecCmdWait(_ *Command, cmd *exec.Cmd) error

ExecCmdWait implements the Executor interface.

func (*RealExecutor) ExecLookPath

func (e *RealExecutor) ExecLookPath(_ *Command, file string) (string, error)

ExecLookPath implements the Executor interface.

func (*RealExecutor) OSChdir

func (e *RealExecutor) OSChdir(_ *Command, dir string) error

OSChdir implements the Executor interface.

func (*RealExecutor) SyscallExec

func (e *RealExecutor) SyscallExec(_ *Command, argv0 string, argv []string, envv []string) error

SyscallExec implements the Executor interface.

Directories

Path Synopsis
Package tshellz is a generated GoMock package.
Package tshellz is a generated GoMock package.

Jump to

Keyboard shortcuts

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