execx

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreePort added in v0.2.0

func FreePort(port int)

FreePort releases a TCP port before a service binds to it, so two independent godev projects on the same machine (e.g. two microservices, each defaulting to :5432/:3000) don't have to coordinate port numbers by hand.

It first checks whether a Docker container — from this project or any other — is currently publishing that exact port, and if so stops just that one container (docker stop, never a teardown of its whole stack). Only when no container owns the port does it fall back to killing a bare local process on it, and even then it refuses to touch anything that looks like the container engine itself (see dockerEngineProcessNames).

func LookPath added in v0.4.0

func LookPath(name string) (string, error)

LookPath reports where an executable is installed.

func OpenBrowser

func OpenBrowser(target string)

OpenBrowser opens a file or URL in the default browser (preferring Google Chrome on Mac)

func Output added in v0.4.0

func Output(name string, args ...string) ([]byte, error)

Output executes a command and returns its stdout.

func Run

func Run(name string, args ...string) error

Run executes a command streaming stdout/stderr to standard OS outputs

func RunQuiet added in v0.4.0

func RunQuiet(name string, args ...string) error

RunQuiet executes a command without printing its output. On failure the error includes what the command wrote to stderr.

func RunWithEnv

func RunWithEnv(env map[string]string, name string, args ...string) error

RunWithEnv executes a command with additional environment variables

func RunWithInput added in v0.4.0

func RunWithInput(stdin []byte, name string, args ...string) error

RunWithInput executes a command feeding stdin to it and streaming its output.

func SetRunner added in v0.4.0

func SetRunner(r Runner) (restore func())

SetRunner replaces the package-level runner and returns a function that restores the previous one. It is meant for tests.

func StartBackground

func StartBackground(ctx context.Context, env map[string]string, name string, args ...string) (*exec.Cmd, error)

StartBackground starts a long-running process in background with custom env and context

func WaitForURL

func WaitForURL(urlStr string, timeout time.Duration) error

WaitForURL polls an HTTP endpoint until it responds with a non-5xx status code or times out

Types

type Cmd added in v0.4.0

type Cmd struct {
	Name string
	Args []string
	// Env holds variables added on top of the current environment.
	Env map[string]string
	// Stdin is fed to the process. When nil, a streamed command inherits the
	// terminal's stdin.
	Stdin []byte
	// Quiet discards the process output instead of streaming it to the terminal.
	// On failure the returned error includes what the process wrote to stderr.
	Quiet bool
}

Cmd describes a single process invocation.

func (Cmd) String added in v0.4.0

func (c Cmd) String() string

String renders the command line, mainly for logs and test assertions.

type OSRunner added in v0.4.0

type OSRunner struct{}

OSRunner is the Runner that executes real processes.

func (OSRunner) LookPath added in v0.4.0

func (OSRunner) LookPath(name string) (string, error)

LookPath implements Runner.

func (OSRunner) Output added in v0.4.0

func (r OSRunner) Output(c Cmd) ([]byte, error)

Output implements Runner.

func (OSRunner) Run added in v0.4.0

func (r OSRunner) Run(c Cmd) error

Run implements Runner.

type Runner added in v0.4.0

type Runner interface {
	// Run executes c to completion, streaming its output unless c.Quiet is set.
	Run(c Cmd) error
	// Output executes c and returns its stdout. Stderr is folded into the error.
	Output(c Cmd) ([]byte, error)
	// LookPath reports where an executable is installed, like exec.LookPath.
	LookPath(name string) (string, error)
}

Runner executes external processes. Every command godev launches to completion goes through the package-level runner, so tests can replace it with SetRunner (see the execxtest package) instead of running real tools.

Directories

Path Synopsis
Package execxtest provides a fake execx.Runner that records every command instead of running it.
Package execxtest provides a fake execx.Runner that records every command instead of running it.

Jump to

Keyboard shortcuts

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