shell

package
v0.0.0-...-ac6d1fa Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LogDisabledLevel is a fake logrus log level, that is used by ExecBuilder to represent that logging should be
	// disabled.
	LogDisabledLevel logrus.Level = math.MaxUint32

	// DefaultWarnLogLines is a default value that can be used with the WarnLogLines function.
	DefaultWarnLogLines int = 1500
)
View Source
const ShellProgram = "/bin/bash"

ShellProgram is the default shell program used by the tooling.

Variables

This section is empty.

Functions

func CurrentEnvironment

func CurrentEnvironment() []string

CurrentEnvironment returns the current environment variables that are being used for all processes launched from this package.

func Execute

func Execute(program string, args ...string) (stdout, stderr string, err error)

Execute runs the provided command.

func ExecuteAndLogToFile

func ExecuteAndLogToFile(filepath string, command string, args ...string)

ExecuteAndLogToFile runs a command in the shell and redirects stdout to the given file

func ExecuteLive

func ExecuteLive(squashErrors bool, program string, args ...string) (err error)

ExecuteLive runs a command in the shell and logs it in real-time

func ExecuteLiveWithErr

func ExecuteLiveWithErr(stderrLines int, program string, args ...string) (err error)

ExecuteLiveWithErr runs a command in the shell and logs it in real-time. In addition, if there is an error, the last x lines of stderr will be attached to the err object.

func ExecuteWithStdin

func ExecuteWithStdin(input, program string, args ...string) (stdout, stderr string, err error)

ExecuteWithStdin - Run the command and use Stdin to pass input during execution

func MustExecuteLive

func MustExecuteLive(command string, args ...string)

MustExecuteLive executes the shell command. Panics on failure.

func PermanentlyStopAllChildProcesses

func PermanentlyStopAllChildProcesses(signal unix.Signal)

PermanentlyStopAllChildProcesses will send the provided signal to all processes spawned by this package, and all of those process's children. Invoking this will also block future process creation, causing the Execute methods to return an error. Be aware that this will block the gpg-agent cleanup mechanism from running, which may cause chroots to not unmount properly. Consider using StopAllChildProcesses instead.

func SetEnvironment

func SetEnvironment(env []string)

SetEnvironment sets the default environment variables to be used for all processes launched from this package.

func StopAllChildProcesses

func StopAllChildProcesses(signal unix.Signal)

StopAllChildProcesses will stop all currently running processes spawned by this package, but will not block future process creation.

Types

type ExecBuilder

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

func NewExecBuilder

func NewExecBuilder(command string, args ...string) ExecBuilder

NewExecBuilder initializes a new execution builder object.

func (ExecBuilder) Callbacks

func (b ExecBuilder) Callbacks(stdoutCallback LogCallback, stderrCallback LogCallback) ExecBuilder

Callbacks sets the callback functions for both stdout and stderr.

func (ExecBuilder) EnvironmentVariables

func (b ExecBuilder) EnvironmentVariables(environmentVariables []string) ExecBuilder

EnvironmentVariables sets the complete list of environment variables for the command to be executed.

func (ExecBuilder) ErrorStderrLines

func (b ExecBuilder) ErrorStderrLines(lines int) ExecBuilder

ErrorStderrLines sets the number of stderr lines to add to the error object, if the execution fails.

func (ExecBuilder) Execute

func (b ExecBuilder) Execute() error

func (ExecBuilder) ExecuteCaptureOuput

func (b ExecBuilder) ExecuteCaptureOuput() (string, string, error)

func (ExecBuilder) LogLevel

func (b ExecBuilder) LogLevel(stdoutLogLevel logrus.Level, stderrLogLevel logrus.Level) ExecBuilder

Sets the log level for stdout and stderr lines.

func (ExecBuilder) StderrCallback

func (b ExecBuilder) StderrCallback(stderrCallback LogCallback) ExecBuilder

StderrCallback sets a callback function that it called for each line of stderr.

func (ExecBuilder) StderrLogLevel

func (b ExecBuilder) StderrLogLevel(stderrLogLevel logrus.Level) ExecBuilder

Sets the log level for stderr lines.

func (ExecBuilder) Stdin

func (b ExecBuilder) Stdin(value string) ExecBuilder

Stdin sets a string value to be passed to the process via stdin.

func (ExecBuilder) StdoutCallback

func (b ExecBuilder) StdoutCallback(stdoutCallback LogCallback) ExecBuilder

StdoutCallback sets a callback function that it called for each line of stdout.

func (ExecBuilder) StdoutLogLevel

func (b ExecBuilder) StdoutLogLevel(stdoutLogLevel logrus.Level) ExecBuilder

Sets the log level for stdout lines.

func (ExecBuilder) WarnLogLines

func (b ExecBuilder) WarnLogLines(lines int) ExecBuilder

WarnLogLines sets the number of stdout/stderr lines that will be printed as warning logs if the process returns an error.

Note: This function exists for the sake of compatability with existing code. It is generally preferable to set the stdout and stderr log levels to an appropriate value.

func (ExecBuilder) WorkingDirectory

func (b ExecBuilder) WorkingDirectory(path string) ExecBuilder

WorkingDirectory sets the working directory for the command to be executed.

type LogCallback

type LogCallback func(line string)

Jump to

Keyboard shortcuts

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