shell

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package shell provides process execution and shell operations.

Package shell provides process execution and shell operations.

Package shell provides process execution and shell operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// SetVerbose configures verbose logging output.
	SetVerbose = logger.SetVerbose
	// MultiPrinter handles concurrent output formatting.
	MultiPrinter = logger.MultiPrinter
)

Functions

func Exec

func Exec(ctx context.Context, excludeStdout bool, dir, name string, args ...string) error

Exec executes a command in the specified directory with optional stdout exclusion.

func ExecCapture added in v2.2.0

func ExecCapture(ctx context.Context, out io.Writer, dir, name string, args ...string,
) error

ExecCapture runs the command with stdout and stderr written to out. Use this when a caller needs to collect process output into a buffer (e.g. MCP session logs) instead of streaming it via the global MultiPrinter. Internally relies on os/exec.CommandContext with out as the combined sink; no extra dependencies.

func ExecWithContext

func ExecWithContext(
	ctx context.Context, excludeStdout bool, dir, name string, args ...string,
) error

ExecWithContext executes a command with context for cancellation control.

func ExecWithSudo

func ExecWithSudo(ctx context.Context, excludeStdout bool, dir, name string, args ...string) error

ExecWithSudo executes a command with sudo if the user is not running as root. This is specifically for package manager commands that need elevated privileges.

func ExecWithSudoContext

func ExecWithSudoContext(
	ctx context.Context, excludeStdout bool, dir, name string, args ...string,
) error

ExecWithSudoContext executes a command with sudo if needed, with context for cancellation.

func Join added in v2.2.0

func Join(args []string) string

Join single-quotes each arg and joins them with a space — suitable for concatenating an argv into a single `/bin/sh -c` script.

func RunScript

func RunScript(cmds string) error

RunScript executes a shell script from a string.

func RunScriptInFakeroot

func RunScriptInFakeroot(ctx context.Context, cmds, packageName string, extraEnv ...[]string) error

RunScriptInFakeroot executes a shell script identically to RunScriptWithPackage but wraps every subprocess in a Linux user-namespace fakeroot so that ownership operations (install -o root, chown, etc.) succeed without real root privileges. Use this for the package() stage of PKGBUILD execution.

func RunScriptWithPackage

func RunScriptWithPackage(ctx context.Context, cmds, packageName string, extraEnv ...[]string) error

RunScriptWithPackage executes a shell script with package-specific output formatting. An optional extraEnv slice of "KEY=VALUE" pairs may be supplied; each entry overrides or extends the inherited process environment for this script invocation only, without mutating os.Environ(). This makes the function safe to call concurrently from parallel build goroutines.

func SingleQuote added in v2.2.0

func SingleQuote(s string) string

SingleQuote wraps s in single quotes, escaping any inner single quote via the standard POSIX `'\”` trick. Safe for use in arbitrary `/bin/sh -c` command bodies. The empty string returns `”`.

Types

type GitProgressWriter

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

GitProgressWriter handles git command output with progress formatting.

func NewGitProgressWriter

func NewGitProgressWriter(writer io.Writer, packageName string) *GitProgressWriter

NewGitProgressWriter creates a new GitProgressWriter instance.

func (*GitProgressWriter) Close

func (gpw *GitProgressWriter) Close() error

Close returns the buffer to the pool and should be called when done with the writer.

func (*GitProgressWriter) Write

func (gpw *GitProgressWriter) Write(p []byte) (int, error)

type PackageDecoratedWriter

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

PackageDecoratedWriter decorates output with package name prefixes.

func NewPackageDecoratedWriter

func NewPackageDecoratedWriter(writer io.Writer, packageName string) *PackageDecoratedWriter

NewPackageDecoratedWriter creates a new PackageDecoratedWriter instance.

func (*PackageDecoratedWriter) Close

func (pdw *PackageDecoratedWriter) Close() error

Close returns the buffer to the pool and should be called when done with the writer.

func (*PackageDecoratedWriter) Write

func (pdw *PackageDecoratedWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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