exec

package
v0.0.4-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: EUPL-1.2 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunQuiet

func RunQuiet(ctx context.Context, name string, args ...string) error

RunQuiet executes the command suppressing stdout unless there is an error. Useful for internal commands.

func SetDefaultLogger

func SetDefaultLogger(l Logger)

SetDefaultLogger sets the package-level default logger. Commands without an explicit logger will use this.

Types

type Cmd

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

Cmd represents a wrapped command

func Command

func Command(ctx context.Context, name string, args ...string) *Cmd

Command wraps os/exec.Command with logging and context

func (*Cmd) CombinedOutput

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

CombinedOutput runs the command and returns its combined standard output and standard error.

func (*Cmd) Output

func (c *Cmd) Output() ([]byte, error)

Output runs the command and returns its standard output.

func (*Cmd) Run

func (c *Cmd) Run() error

Run executes the command and waits for it to finish. It automatically logs the command execution at debug level.

func (*Cmd) WithDir

func (c *Cmd) WithDir(dir string) *Cmd

WithDir sets the working directory

func (*Cmd) WithEnv

func (c *Cmd) WithEnv(env []string) *Cmd

WithEnv sets the environment variables

func (*Cmd) WithLogger

func (c *Cmd) WithLogger(l Logger) *Cmd

WithLogger sets a custom logger for this command. If not set, the package default logger is used.

func (*Cmd) WithStderr

func (c *Cmd) WithStderr(w io.Writer) *Cmd

WithStderr sets stderr

func (*Cmd) WithStdin

func (c *Cmd) WithStdin(r io.Reader) *Cmd

WithStdin sets stdin

func (*Cmd) WithStdout

func (c *Cmd) WithStdout(w io.Writer) *Cmd

WithStdout sets stdout

type Logger

type Logger interface {
	// Debug logs a debug-level message with optional key-value pairs.
	Debug(msg string, keyvals ...any)
	// Error logs an error-level message with optional key-value pairs.
	Error(msg string, keyvals ...any)
}

Logger interface for command execution logging. Compatible with pkg/log.Logger and other structured loggers.

func DefaultLogger

func DefaultLogger() Logger

DefaultLogger returns the current default logger.

type NopLogger

type NopLogger struct{}

NopLogger is a no-op logger that discards all messages.

func (NopLogger) Debug

func (NopLogger) Debug(string, ...any)

Debug discards the message (no-op implementation).

func (NopLogger) Error

func (NopLogger) Error(string, ...any)

Error discards the message (no-op implementation).

type Options

type Options struct {
	Dir    string
	Env    []string
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

Options configuration for command execution

Jump to

Keyboard shortcuts

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