env

package
v0.97.8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package env provides filesystem and shell execution with Result-based error handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatExecOutput

func FormatExecOutput(capture Capture, isError bool, err error) string

FormatExecOutput formats capture output for tool results.

func FormatExecutionError

func FormatExecutionError(err result.ExecutionError) string

FormatExecutionError returns a tool-facing message for an ExecutionError.

func FormatFileError

func FormatFileError(err result.FileError) string

FormatFileError returns a tool-facing message for a FileError.

Types

type Capture

type Capture struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

Capture holds combined shell output from Exec.

type DirEntry added in v0.97.8

type DirEntry struct {
	// Name is the entry basename.
	Name string
	// IsDir reports whether the entry is a directory.
	IsDir bool
}

DirEntry describes one filesystem entry from ReadDir.

type ExecOptions

type ExecOptions struct {
	// Command runs through the platform shell when Argv is empty.
	Command string
	// Argv runs the binary directly without a shell when non-empty.
	Argv []string
	Dir  string
	// Timeout is the context governing cancellation and deadlines.
	Timeout context.Context
}

ExecOptions configures a shell command invocation.

type ExecutionEnv

type ExecutionEnv interface {
	ReadFile(ctx context.Context, path string) result.Result[[]byte, result.FileError]
	WriteFile(ctx context.Context, path string, data []byte, perm os.FileMode) result.Result[struct{}, result.FileError]
	MkdirAll(ctx context.Context, path string, perm os.FileMode) result.Result[struct{}, result.FileError]
	Remove(ctx context.Context, path string) result.Result[struct{}, result.FileError]
	ReadDir(ctx context.Context, path string) result.Result[[]DirEntry, result.FileError]
	Exec(ctx context.Context, opts ExecOptions) result.Result[Capture, result.ExecutionError]
}

ExecutionEnv performs filesystem and shell operations without throwing untyped errors.

func Default

func Default() ExecutionEnv

Default returns the OS-backed execution environment.

type OSExecutionEnv

type OSExecutionEnv struct{}

OSExecutionEnv implements ExecutionEnv using the local operating system.

func (OSExecutionEnv) Exec

Exec runs a shell command or direct argv invocation and captures output.

func (OSExecutionEnv) MkdirAll

func (OSExecutionEnv) MkdirAll(_ context.Context, path string, perm os.FileMode) result.Result[struct{}, result.FileError]

MkdirAll creates a directory tree.

func (OSExecutionEnv) ReadDir added in v0.97.8

ReadDir lists directory entries.

func (OSExecutionEnv) ReadFile

ReadFile reads file contents from disk.

func (OSExecutionEnv) Remove

func (OSExecutionEnv) Remove(_ context.Context, path string) result.Result[struct{}, result.FileError]

Remove deletes a file or empty directory.

func (OSExecutionEnv) WriteFile

func (OSExecutionEnv) WriteFile(_ context.Context, path string, data []byte, perm os.FileMode) result.Result[struct{}, result.FileError]

WriteFile writes data to a file path.

Jump to

Keyboard shortcuts

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