Documentation
¶
Overview ¶
Package env provides filesystem and shell execution with Result-based error handling.
Index ¶
- func FormatExecOutput(capture Capture, isError bool, err error) string
- func FormatExecutionError(err result.ExecutionError) string
- func FormatFileError(err result.FileError) string
- type Capture
- type ExecOptions
- type ExecutionEnv
- type OSExecutionEnv
- func (OSExecutionEnv) Exec(ctx context.Context, opts ExecOptions) result.Result[Capture, result.ExecutionError]
- func (OSExecutionEnv) MkdirAll(_ context.Context, path string, perm os.FileMode) result.Result[struct{}, result.FileError]
- func (OSExecutionEnv) ReadFile(_ context.Context, path string) result.Result[[]byte, result.FileError]
- func (OSExecutionEnv) Remove(_ context.Context, path string) result.Result[struct{}, result.FileError]
- func (OSExecutionEnv) WriteFile(_ context.Context, path string, data []byte, perm os.FileMode) result.Result[struct{}, result.FileError]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatExecOutput ¶
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 ¶
FormatFileError returns a tool-facing message for a FileError.
Types ¶
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]
Exec(ctx context.Context, opts ExecOptions) result.Result[Capture, result.ExecutionError]
}
ExecutionEnv performs filesystem and shell operations without throwing untyped errors.
type OSExecutionEnv ¶
type OSExecutionEnv struct{}
OSExecutionEnv implements ExecutionEnv using the local operating system.
func (OSExecutionEnv) Exec ¶
func (OSExecutionEnv) Exec(ctx context.Context, opts ExecOptions) result.Result[Capture, result.ExecutionError]
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) ReadFile ¶
func (OSExecutionEnv) ReadFile(_ context.Context, path string) result.Result[[]byte, result.FileError]
ReadFile reads file contents from disk.
Click to show internal directories.
Click to hide internal directories.