localexec

package
v0.33.20 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package localexec provides constructs for uniform execution of local processes, specifically conversion from model.Cmd to exec.Cmd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OneShotToLogger added in v0.23.0

func OneShotToLogger(ctx context.Context, execer Execer, cmd model.Cmd) error

Types

type Env added in v0.22.1

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

Common environment for local exec commands.

func DefaultEnv added in v0.22.1

func DefaultEnv(port model.WebPort, host model.WebHost) *Env

func EmptyEnv added in v0.22.1

func EmptyEnv() *Env

func (*Env) Add added in v0.22.1

func (e *Env) Add(k, v string)

func (*Env) ExecCmd added in v0.22.1

func (e *Env) ExecCmd(cmd model.Cmd, l logger.Logger) (*exec.Cmd, error)

ExecCmd creates a stdlib exec.Cmd instance suitable for execution by the local engine.

The resulting command will inherit the parent process (i.e. `tilt`) environment, then have command specific environment overrides applied, and finally, additional conditional environment to improve logging output.

NOTE: To avoid confusion with ExecCmdContext, this method accepts a logger instance directly rather than using logger.Get(ctx); the returned exec.Cmd from this function will NOT be associated with any context.

type Execer added in v0.23.0

type Execer interface {
	// Run executes a command and waits for it to complete.
	//
	// If the context is canceled before the process terminates, the process will be killed.
	Run(ctx context.Context, cmd model.Cmd, runIO RunIO) (int, error)
}

type FakeCall added in v0.23.0

type FakeCall struct {
	Cmd      model.Cmd
	ExitCode int
	Error    error
}

func (FakeCall) String added in v0.23.0

func (f FakeCall) String() string

type FakeExecer added in v0.23.0

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

func NewFakeExecer added in v0.23.0

func NewFakeExecer(t testing.TB) *FakeExecer

func (*FakeExecer) Calls added in v0.23.0

func (f *FakeExecer) Calls() []FakeCall

func (*FakeExecer) RegisterCommand added in v0.23.0

func (f *FakeExecer) RegisterCommand(cmd string, exitCode int, stdout string, stderr string)

RegisterCommand adds or replaces a command to the FakeExecer.

If the output strings are not newline terminated, a newline will automatically be added. If this behavior is not desired, use `RegisterCommandBytes`.

func (*FakeExecer) RegisterCommandBytes added in v0.23.0

func (f *FakeExecer) RegisterCommandBytes(cmd string, exitCode int, stdout []byte, stderr []byte)

RegisterCommandBytes adds or replaces a command to the FakeExecer.

The output values will be used exactly as-is, so can be used to simulate processes that do not newline terminate etc.

func (*FakeExecer) RegisterCommandError added in v0.23.0

func (f *FakeExecer) RegisterCommandError(cmd string, err error)

func (*FakeExecer) Run added in v0.23.0

func (f *FakeExecer) Run(ctx context.Context, cmd model.Cmd, runIO RunIO) (exitCode int, err error)

type OneShotResult added in v0.23.0

type OneShotResult struct {
	// ExitCode from the process
	ExitCode int
	// Stdout from the process
	Stdout []byte
	// Stderr from the process
	Stderr []byte
}

OneShotResult includes details about command execution.

func OneShot added in v0.23.0

func OneShot(ctx context.Context, execer Execer, cmd model.Cmd) (OneShotResult, error)

type ProcessExecer added in v0.23.0

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

func NewProcessExecer added in v0.23.0

func NewProcessExecer(env *Env) *ProcessExecer

func (ProcessExecer) Run added in v0.23.0

func (p ProcessExecer) Run(ctx context.Context, cmd model.Cmd, runIO RunIO) (int, error)

type RunIO added in v0.23.0

type RunIO struct {
	// Stdin for the process
	Stdin io.Reader
	// Stdout for the process
	Stdout io.Writer
	// Stderr for the process
	Stderr io.Writer
}

Jump to

Keyboard shortcuts

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