exec

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package exec provides utilities to execute commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(ctx context.Context, name string, args ...string) error

Exec executes the given command and returns the output.

func IsRunning

func IsRunning(pid int) bool

IsRunning returns true if the process is running.

func KillProcess added in v0.4.0

func KillProcess(pid int) error

KillProcess kills the process with the given pid.

func LookPath

func LookPath(file string) (string, error)

LookPath is a wrapper around exec.LookPath.

func ParseVersionFromBinary added in v0.4.0

func ParseVersionFromBinary(ctx context.Context, path string) (version.Version, error)

ParseVersionFromBinary parses the version from the binary.

func ParseVersionFromImage added in v0.4.0

func ParseVersionFromImage(ctx context.Context, runtime string, image string, command string) (version.Version, error)

ParseVersionFromImage parses the version from the image.

func PullImage added in v0.5.0

func PullImage(ctx context.Context, command string, image string, quiet bool) error

PullImage is a helper function to pull image

func PullImages added in v0.4.0

func PullImages(ctx context.Context, command string, images []string, quiet bool) error

PullImages is a helper function to pull images

func WithAllWriteTo added in v0.2.0

func WithAllWriteTo(ctx context.Context, w io.Writer) context.Context

WithAllWriteTo returns a context with the given io.Writer as the In, Out, and ErrOut streams.

func WithAllWriteToErrOut added in v0.2.0

func WithAllWriteToErrOut(ctx context.Context) context.Context

WithAllWriteToErrOut returns a context with the given io.Writer as the ErrOut stream.

func WithDir added in v0.2.0

func WithDir(ctx context.Context, dir string) context.Context

WithDir returns a context with the given working directory.

func WithEnv added in v0.2.0

func WithEnv(ctx context.Context, env []string) context.Context

WithEnv returns a context with the given environment variables.

func WithFork added in v0.4.0

func WithFork(ctx context.Context, fork bool) context.Context

WithFork returns a context with the given fork option.

func WithIOStreams added in v0.2.0

func WithIOStreams(ctx context.Context, streams IOStreams) context.Context

WithIOStreams returns a context with the given IOStreams.

func WithPipeStdin added in v0.2.0

func WithPipeStdin(ctx context.Context, pipeStdin bool) context.Context

WithPipeStdin returns a context with the given pipeStdin option.

func WithReadFrom added in v0.5.0

func WithReadFrom(ctx context.Context, r io.Reader) context.Context

WithReadFrom returns a context with the given io.Reader as the In stream.

func WithReadWriter added in v0.2.0

func WithReadWriter(ctx context.Context, rw io.ReadWriter) context.Context

WithReadWriter returns a context with the given io.ReadWriter as the In and Out streams.

func WithStdIO added in v0.2.0

func WithStdIO(ctx context.Context) context.Context

WithStdIO returns a context with the standard IOStreams.

func WithUser added in v0.4.0

func WithUser(ctx context.Context, uid, gid *int64) context.Context

WithUser returns a context with the given username and group name.

func WithWriteTo added in v0.2.0

func WithWriteTo(ctx context.Context, w io.Writer) context.Context

WithWriteTo returns a context with the given io.Writer as the Out stream.

Types

type Cmd added in v0.5.0

type Cmd = exec.Cmd

func Command added in v0.4.0

func Command(ctx context.Context, name string, args ...string) (cmd *Cmd, err error)

Command executes the given command and return the command.

type IOStreams

type IOStreams struct {
	// In think, os.Stdin
	In io.Reader
	// Out think, os.Stdout
	Out io.Writer
	// ErrOut think, os.Stderr
	ErrOut io.Writer
}

IOStreams contains the standard streams.

type Options added in v0.4.0

type Options struct {
	// Dir is the working directory of the command.
	Dir string
	// Env is the environment variables of the command.
	Env []string
	// UID is the user id of the command
	UID *int64
	// GID is the group id of the command
	GID *int64
	// IOStreams contains the standard streams.
	IOStreams
	// PipeStdin is true if the command's stdin should be piped.
	PipeStdin bool
	// Fork is true if the command should be forked.
	Fork bool
}

Options is the options for executing a command.

func GetExecOptions added in v0.4.0

func GetExecOptions(ctx context.Context) *Options

GetExecOptions returns the ExecOptions for the given context.

Jump to

Keyboard shortcuts

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