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 ¶
- func RunCommand(ctx context.Context, cmd *invoke.Command, opts ...invoke.ExecOption) (*invoke.BufferedResult, error)
- func RunShell(ctx context.Context, script string, opts ...invoke.ExecOption) (*invoke.BufferedResult, error)
- type Config
- type Environment
- func (e *Environment) ActiveProcesses() int
- func (e *Environment) Close() error
- func (e *Environment) Download(ctx context.Context, remotePath, localPath string, opts ...invoke.FileOption) error
- func (e *Environment) LookPath(_ context.Context, file string) (string, error)
- func (e *Environment) Run(ctx context.Context, cmd *invoke.Command) (*invoke.Result, error)
- func (e *Environment) Start(ctx context.Context, cmd *invoke.Command) (invoke.Process, error)
- func (e *Environment) TargetOS() invoke.TargetOS
- func (e *Environment) Upload(ctx context.Context, localPath, remotePath string, opts ...invoke.FileOption) error
- type Option
- type Process
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 (*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 ¶
LookPath searches for an executable named file in the directories named by the PATH environment variable.
func (*Environment) Start ¶
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 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 ¶
Close releases resources associated with the process. If the process is still running, it will be killed to ensure cleanup.