Documentation
¶
Overview ¶
Package command provides helpers to execute external commands with logging.
Index ¶
- Constants
- Variables
- func GetExecutablePath(commandOverrides map[string]string, commandName string) string
- func Output(ctx context.Context, command string, arg ...string) (string, error)
- func OutputWithEnv(ctx context.Context, env map[string]string, command string, arg ...string) (string, error)
- func Run(ctx context.Context, command string, arg ...string) error
- func RunInDir(ctx context.Context, dir, command string, arg ...string) error
- func RunInDirWithEnv(ctx context.Context, dir string, env map[string]string, command string, ...) error
- func RunStreaming(ctx context.Context, command string, arg ...string) error
- func RunWithEnv(ctx context.Context, env map[string]string, command string, arg ...string) error
Constants ¶
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 ¶
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
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
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 ¶
Run executes a program (with arguments). On error, stderr is included in the error message. It is a convenience wrapper around RunWithEnv.
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
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
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.