command

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 License: Apache-2.0 Imports: 9 Imported by: 32

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunStdout

func RunStdout(
	ctx context.Context,
	container app.EnvStdioContainer,
	runner Runner,
	name string,
	args ...string,
) ([]byte, error)

RunStdout is a convenience function that attaches the container environment, stdin, and stderr, and returns the stdout as a byte slice.

Types

type RunOption

type RunOption func(*runOptions)

RunOption is an option for Run.

func RunWithArgs

func RunWithArgs(args ...string) RunOption

RunWithArgs returns a new RunOption that sets the arguments other than the name.

The default is no arguments.

func RunWithDir

func RunWithDir(dir string) RunOption

RunWithDir returns a new RunOption that sets the working directory.

The default is the current working directory.

func RunWithEnv

func RunWithEnv(env map[string]string) RunOption

RunWithEnv returns a new RunOption that sets the environment variables.

The default is to use the single environment variable __EMPTY_ENV__=1 as we cannot explicitly set an empty environment with the exec package.

func RunWithStderr

func RunWithStderr(stderr io.Writer) RunOption

RunWithStderr returns a new RunOption that sets the stderr.

The default is io.Discard.

func RunWithStdin

func RunWithStdin(stdin io.Reader) RunOption

RunWithStdin returns a new RunOption that sets the stdin.

The default is ioextended.DiscardReader.

func RunWithStdout

func RunWithStdout(stdout io.Writer) RunOption

RunWithStdout returns a new RunOption that sets the stdout.

The default is io.Discard.

type Runner

type Runner interface {
	// Run runs the external command.
	//
	// This should be used instead of exec.CommandContext(...).Run().
	Run(ctx context.Context, name string, options ...RunOption) error
}

Runner runs external commands.

A Runner will limit the number of concurrent commands, as well as explicitly set stdin, stdout, stderr, and env to nil/empty values if not set with options.

All external commands in buf MUST use command.Runner instead of exec.Command, exec.CommandContext.

func NewRunner

func NewRunner(options ...RunnerOption) Runner

NewRunner returns a new Runner.

type RunnerOption

type RunnerOption func(*runner)

RunnerOption is an option for a new Runner.

func RunnerWithParallelism

func RunnerWithParallelism(parallelism int) RunnerOption

RunnerWithParallelism returns a new Runner that sets the number of external commands that can be run concurrently.

The default is thread.Parallelism().

Jump to

Keyboard shortcuts

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