exec

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStderr

func GetStderr(err error) (string, bool)

GetStderr returns the stderr from a RunX error

func NewExecErr

func NewExecErr(message string, stderr string, exitCode int) error

func StderrNotEmpty added in v0.4.0

func StderrNotEmpty(stderr string, ok bool) (string, bool)

StderrNotEmpty checks if the stderr is truly not empty

func TrimStdout

func TrimStdout(o string, err error) (string, error)

TrimStdout for convenience as RunX does not return a result where you can get the Result.TrimStdout but instead the stdout.

Types

type Execer

type Execer interface {
	// Run executes a command with the repository's folder as working dir
	Run(ctx context.Context, command string, args ...string) (Result, error)
	// RunX executes a command with repository's folder as working dir. It will return an error
	// if exit code is non zero.
	RunX(ctx context.Context, command string, args ...string) (string, error)
	// Run executes a command with the repository's folder as working dir accepting a stdin
	RunWithStdin(ctx context.Context, stdin io.Reader, command string, args ...string) (Result, error)
	// RunWithStdin executes a command with the repository's folder as working dir accepting a stdin and returning the stdout
	RunWithStdinX(ctx context.Context, stdin io.Reader, command string, args ...string) (string, error)
	// Log logs a message with the given level and fields
	Log(ctx context.Context, level slog.Level, msg string, fields ...any)

	// DebugShell starts a shell session in the execer's directory
	DebugShell(ctx context.Context)

	// WithEnv creates a child execer with added env variables
	WithEnv(kv ...string) Execer
	// WithLogFields creates a child execer with added log fields
	WithLogFields(kvFields ...any) Execer
	// Sub creates a new execer in an existing subpath.
	Sub(subpath string) (Execer, error)
	// GenerateFS returns a FS object relative to the exec dir to interact with
	GenerateFS() afero.Fs
}

Execer defines an interface to execute commands in a given directory with optional environment variables and logging capabilities.

func NewExecer

func NewExecer(dir string) Execer

NewExecer creates a new execer

func NewExecerWithLogger

func NewExecerWithLogger(dir string, logger *slog.Logger) Execer

NewExecerWithLogger creates a new execer with a logger

type Result

type Result struct {
	Stdout    string
	Stderr    string
	ExitCode  int
	Cancelled bool
}

Result holds the result from a command run

func (Result) TrimStdout

func (r Result) TrimStdout() string

TrimStdout returns the content of stdout removing the trailing new lines.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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