exec

package
v0.0.0-...-0816722 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandExecutor

type CommandExecutor struct{}

CommandExecutor is an Executor type

func (*CommandExecutor) RunCommandAsHost

func (e *CommandExecutor) RunCommandAsHost(ctx context.Context, command string, arg ...string) error

RunCommandAsHost executes a command as host and returns an error if the command fails. it finishes the run and the output will be printed to the log.

func (*CommandExecutor) RunCommandAsHostInto

func (e *CommandExecutor) RunCommandAsHostInto(ctx context.Context, into any, command string, arg ...string) error

RunCommandAsHostInto executes a command as host and returns an error if the command fails. it finishes the run and decodes the output via JSON into the provided struct pointer. if the struct pointer is nil, the output will be printed to the log instead.

func (*CommandExecutor) StartCommandWithOutputAsHost

func (*CommandExecutor) StartCommandWithOutputAsHost(ctx context.Context, command string, arg ...string) (io.ReadCloser, error)

StartCommandWithOutputAsHost executes a command with output as host and returns the output as a ReadCloser. The caller is responsible for closing the ReadCloser. Not calling close on this method will result in a resource leak.

type Error

type Error interface {
	error
	ExitCode() int
	Unwrap() error
}

Error is an error that wraps the original error and the stderr output of the command if found. It also provides an exit code if present that can be used to determine the type of error.

func AsExecError

func AsExecError(err error) (Error, bool)

AsExecError returns the Error from the error if it exists and a bool indicating if is an Error or not.

type Executor

type Executor interface {
	StartCommandWithOutputAsHost(ctx context.Context, command string, arg ...string) (io.ReadCloser, error)
	RunCommandAsHost(ctx context.Context, command string, arg ...string) error
	RunCommandAsHostInto(ctx context.Context, into any, command string, arg ...string) error
}

Executor is the interface for running exec commands

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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