command

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package command provides helpers to execute external commands with logging.

Index

Constants

View Source
const (
	// Cargo is the command name for the cargo executable.
	Cargo = "cargo"
	// Git is the command name for the git executable.
	Git = "git"
	// Go is the command name for the go executable.
	Go = "go"
)

Variables

View Source
var (
	// Verbose controls whether commands are printed to stderr before execution.
	//
	// TODO(https://github.com/googleapis/librarian/issues/3687): pass in as
	// config.
	Verbose bool
)

Functions

func GetExecutablePath added in v0.8.0

func GetExecutablePath(commandOverrides map[string]string, commandName string) string

GetExecutablePath finds the path for a given command, checking for an override in the provided commandOverrides map first.

func Output added in v0.8.1

func Output(ctx context.Context, command string, arg ...string) (string, error)

Output executes a program (with arguments) and returns stdout. It is a convenience wrapper around OutputWithEnv.

func OutputWithEnv added in v0.8.1

func OutputWithEnv(ctx context.Context, env map[string]string, command string, arg ...string) (string, error)

OutputWithEnv executes a program (with arguments) and optional environment variables and returns stdout. If env is nil or empty, the command inherits the environment of the calling process. On error, stderr is included in the error message.

func Run

func Run(ctx context.Context, command string, arg ...string) error

Run executes a program (with arguments). On error, stderr is included in the error message. It is a convenience wrapper around RunWithEnv.

func RunInDir added in v0.8.1

func RunInDir(ctx context.Context, dir, command string, arg ...string) error

RunInDir executes a program in a specific directory.

func RunInDirWithEnv added in v0.9.1

func RunInDirWithEnv(ctx context.Context, dir string, env map[string]string, command string, arg ...string) error

RunInDirWithEnv executes a program in a specific directory with optional environment variables.

func RunStreaming added in v0.8.4

func RunStreaming(ctx context.Context, command string, arg ...string) error

RunStreaming runs the given binary with the specified args, setting its output and errors streams to those of the current process. The output is not otherwise captured. This is primarily for use in tools which call potentially long-running commands. It should not be used within librarian itself, where the Run and Output functions are generally preferred, as those observe the Verbose flag for output. The Verbose flag only affects the behavior of this function in terms of whether the command being executed is first written to stdout.

func RunWithEnv added in v0.8.0

func RunWithEnv(ctx context.Context, env map[string]string, command string, arg ...string) error

RunWithEnv executes a program (with arguments) and optional environment variables and captures any error output. If env is nil or empty, the command inherits the environment of the calling process.

Types

This section is empty.

Jump to

Keyboard shortcuts

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