Documentation
¶
Index ¶
- func FreePort(port int)
- func LookPath(name string) (string, error)
- func OpenBrowser(target string)
- func Output(name string, args ...string) ([]byte, error)
- func Run(name string, args ...string) error
- func RunQuiet(name string, args ...string) error
- func RunWithEnv(env map[string]string, name string, args ...string) error
- func RunWithInput(stdin []byte, name string, args ...string) error
- func SetRunner(r Runner) (restore func())
- func StartBackground(ctx context.Context, env map[string]string, name string, args ...string) (*exec.Cmd, error)
- func WaitForURL(urlStr string, timeout time.Duration) error
- type Cmd
- type OSRunner
- type Runner
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 OpenBrowser ¶
func OpenBrowser(target string)
OpenBrowser opens a file or URL in the default browser (preferring Google Chrome on Mac)
func RunQuiet ¶ added in v0.4.0
RunQuiet executes a command without printing its output. On failure the error includes what the command wrote to stderr.
func RunWithEnv ¶
RunWithEnv executes a command with additional environment variables
func RunWithInput ¶ added in v0.4.0
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.
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.
type OSRunner ¶ added in v0.4.0
type OSRunner struct{}
OSRunner is the Runner that executes real processes.
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.