env

package
v0.82.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileKindFile      = "file"
	FileKindDirectory = "directory"
	FileKindSymlink   = "symlink"

	FileErrorAborted          = "aborted"
	FileErrorNotFound         = "not_found"
	FileErrorPermissionDenied = "permission_denied"
	FileErrorNotDirectory     = "not_directory"
	FileErrorIsDirectory      = "is_directory"
	FileErrorInvalid          = "invalid"
	FileErrorNotSupported     = "not_supported"
	FileErrorUnknown          = "unknown"

	ExecutionErrorAborted          = "aborted"
	ExecutionErrorTimeout          = "timeout"
	ExecutionErrorShellUnavailable = "shell_unavailable"
	ExecutionErrorSpawnError       = "spawn_error"
	ExecutionErrorCallbackError    = "callback_error"
	ExecutionErrorUnknown          = "unknown"
)

Variables

This section is empty.

Functions

func SanitizeBinaryOutput

func SanitizeBinaryOutput(str string) string

Types

type CapturedShellResult

type CapturedShellResult struct {
	Output         string
	FullOutputPath string
	Truncated      bool
	ExecResult     ExecResult
}

func ExecuteShellWithCapture

func ExecuteShellWithCapture(ctx context.Context, env *LocalExecutionEnv, command string, maxInlineBytes int) (CapturedShellResult, error)

type CreateDirOptions

type CreateDirOptions struct {
	Recursive bool
}

type ExecOptions

type ExecOptions struct {
	CWD        string
	Env        map[string]string
	InheritEnv *bool
	Timeout    time.Duration
	OnStdout   func(string) error
	OnStderr   func(string) error
}

type ExecResult

type ExecResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

type ExecutionEnv

type ExecutionEnv interface {
	FileSystem
	Shell
}

type ExecutionError

type ExecutionError struct {
	Code string
	Err  error
}

func (*ExecutionError) Error

func (e *ExecutionError) Error() string

func (*ExecutionError) Unwrap

func (e *ExecutionError) Unwrap() error

type FileError

type FileError struct {
	Code string
	Path string
	Err  error
}

func (*FileError) Error

func (e *FileError) Error() string

func (*FileError) Unwrap

func (e *FileError) Unwrap() error

type FileInfo

type FileInfo struct {
	Name    string
	Path    string
	Kind    string
	Size    int64
	ModTime time.Time
}

type FileSystem

type FileSystem interface {
	CWD() string
	AbsolutePath(path string) string
	JoinPath(parts ...string) string
	ReadTextFile(ctx context.Context, path string) (string, error)
	ReadTextLines(ctx context.Context, path string, maxLines int) ([]string, error)
	ReadBinaryFile(ctx context.Context, path string) ([]byte, error)
	WriteFile(ctx context.Context, path string, content []byte) error
	AppendFile(ctx context.Context, path string, content []byte) error
	FileInfo(ctx context.Context, path string) (FileInfo, error)
	ListDir(ctx context.Context, path string) ([]FileInfo, error)
	CanonicalPath(ctx context.Context, path string) (string, error)
	Exists(ctx context.Context, path string) (bool, error)
	CreateDir(ctx context.Context, path string, options CreateDirOptions) error
	Remove(ctx context.Context, path string, options RemoveOptions) error
	CreateTempDir(ctx context.Context, prefix string) (string, error)
	CreateTempFile(ctx context.Context, options TempFileOptions) (string, error)
	Cleanup(ctx context.Context) error
}

type LocalExecutionEnv

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

func MustLocalExecutionEnv

func MustLocalExecutionEnv(cwd string, options ...LocalExecutionOption) *LocalExecutionEnv

func NewLocalExecutionEnv

func NewLocalExecutionEnv(cwd string, options ...LocalExecutionOption) (*LocalExecutionEnv, error)

func (*LocalExecutionEnv) AbsolutePath

func (e *LocalExecutionEnv) AbsolutePath(path string) string

func (*LocalExecutionEnv) AppendFile

func (e *LocalExecutionEnv) AppendFile(ctx context.Context, path string, content []byte) error

func (*LocalExecutionEnv) CWD

func (e *LocalExecutionEnv) CWD() string

func (*LocalExecutionEnv) CanonicalPath

func (e *LocalExecutionEnv) CanonicalPath(ctx context.Context, path string) (string, error)

func (*LocalExecutionEnv) Cleanup

func (e *LocalExecutionEnv) Cleanup(context.Context) error

func (*LocalExecutionEnv) CreateDir

func (e *LocalExecutionEnv) CreateDir(ctx context.Context, path string, options CreateDirOptions) error

func (*LocalExecutionEnv) CreateTempDir

func (e *LocalExecutionEnv) CreateTempDir(ctx context.Context, prefix string) (string, error)

func (*LocalExecutionEnv) CreateTempFile

func (e *LocalExecutionEnv) CreateTempFile(ctx context.Context, options TempFileOptions) (string, error)

func (*LocalExecutionEnv) Exec

func (e *LocalExecutionEnv) Exec(ctx context.Context, command string, options ExecOptions) (ExecResult, error)

func (*LocalExecutionEnv) Exists

func (e *LocalExecutionEnv) Exists(ctx context.Context, path string) (bool, error)

func (*LocalExecutionEnv) FileInfo

func (e *LocalExecutionEnv) FileInfo(ctx context.Context, path string) (FileInfo, error)

func (*LocalExecutionEnv) JoinPath

func (e *LocalExecutionEnv) JoinPath(parts ...string) string

func (*LocalExecutionEnv) ListDir

func (e *LocalExecutionEnv) ListDir(ctx context.Context, path string) ([]FileInfo, error)

func (*LocalExecutionEnv) ReadBinaryFile

func (e *LocalExecutionEnv) ReadBinaryFile(ctx context.Context, path string) ([]byte, error)

func (*LocalExecutionEnv) ReadTextFile

func (e *LocalExecutionEnv) ReadTextFile(ctx context.Context, path string) (string, error)

func (*LocalExecutionEnv) ReadTextLines

func (e *LocalExecutionEnv) ReadTextLines(ctx context.Context, path string, maxLines int) ([]string, error)

func (*LocalExecutionEnv) Remove

func (e *LocalExecutionEnv) Remove(ctx context.Context, path string, options RemoveOptions) error

func (*LocalExecutionEnv) WriteFile

func (e *LocalExecutionEnv) WriteFile(ctx context.Context, path string, content []byte) error

type LocalExecutionOption

type LocalExecutionOption func(*LocalExecutionEnv)

func WithShellPath

func WithShellPath(path string) LocalExecutionOption

type RemoveOptions

type RemoveOptions struct {
	Recursive bool
	Force     bool
}

type Shell

type Shell interface {
	Exec(ctx context.Context, command string, options ExecOptions) (ExecResult, error)
	Cleanup(ctx context.Context) error
}

type TempFileOptions

type TempFileOptions struct {
	Prefix string
	Suffix string
}

Jump to

Keyboard shortcuts

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