local

package module
v0.0.0-...-7f93be3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package local provides an implementation of the invoke.Environment interface for the local operating system.

It serves as a thin wrapper around the standard library's "os/exec" and "os" packages, adapting them to the unified invoke interfaces for Command execution and file transfer.

Usage:

env, err := local.New()
if err != nil {
    return err
}
defer env.Close()

res, err := env.Run(ctx, &invoke.Command{Cmd: "echo", Args: []string{"hello"}})
if err != nil {
    return err
}
_ = res

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunCommand

func RunCommand(ctx context.Context, cmd *invoke.Command, opts ...invoke.ExecOption) (*invoke.BufferedResult, error)

RunCommand executes a fully configured command locally using a new environment.

func RunShell

func RunShell(ctx context.Context, script string, opts ...invoke.ExecOption) (*invoke.BufferedResult, error)

RunShell executes a shell command string locally using a new environment.

Types

type Config

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

Config holds configuration for the local environment.

type Environment

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

Environment implements invoke.Environment for the local operating system. Thread-safe wrapper around os/exec.

func New

func New(opts ...Option) (*Environment, error)

New creates a new local environment.

func (*Environment) ActiveProcesses

func (e *Environment) ActiveProcesses() int

ActiveProcesses returns the number of currently running commands.

func (*Environment) Close

func (e *Environment) Close() error

Close shuts down the environment. New Start calls will fail. Existing processes prevent active count from dropping to zero until finished.

func (*Environment) Download

func (e *Environment) Download(ctx context.Context, remotePath, localPath string, opts ...invoke.FileOption) error

Download copies a remote file/dir to the destination path (also local).

func (*Environment) LookPath

func (e *Environment) LookPath(_ context.Context, file string) (string, error)

LookPath searches for an executable named file in the directories named by the PATH environment variable.

func (*Environment) Run

func (e *Environment) Run(ctx context.Context, cmd *invoke.Command) (*invoke.Result, error)

Run executes a command synchronously on the local machine.

func (*Environment) Start

func (e *Environment) Start(ctx context.Context, cmd *invoke.Command) (invoke.Process, error)

Start begins command execution asynchronously. Caller must close/wait on the returned Process.

func (*Environment) TargetOS

func (e *Environment) TargetOS() invoke.TargetOS

TargetOS returns the operating system of the host machine.

func (*Environment) Upload

func (e *Environment) Upload(ctx context.Context, localPath, remotePath string, opts ...invoke.FileOption) error

Upload copies a local file/dir to the destination path (also local).

type Option

type Option func(*Config)

Option defines a functional option for the local provider.

type Process

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

Process implements invoke.Process for local command execution. It wraps `*exec.Cmd` to provide a uniform interface for waiting, signaling, and result retrieval.

func (*Process) Close

func (p *Process) Close() error

Close releases resources associated with the process. If the process is still running, it will be killed to ensure cleanup.

func (*Process) Signal

func (p *Process) Signal(sig os.Signal) error

Signal sends an OS signal to the running process. It delegates directly to os.Process.Signal.

func (*Process) Wait

func (p *Process) Wait() (*invoke.Result, error)

Wait blocks until the command completes and returns the result. It returns an invoke.ExitError if the command finished with a non-zero exit code, or a different error if the wait itself failed (e.g. context cancellation).

Jump to

Keyboard shortcuts

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