util

package
v0.96.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureNewline

func EnsureNewline(b []byte) []byte

EnsureNewline adds a trailing newline if not already there.

func MakeWalkFunc

func MakeWalkFunc(a *txtar.Archive) fs.WalkDirFunc

func Remove

func Remove(ctx context.Context, path string)

Remove cleans up path, useful for temporary directories.

func RunInteractiveCmd

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

RunInteractiveCmd runs a command within a context but allows the command to accept stdin interactively from the user. The caller is expected to handle errors.

Types

type RunResult

type RunResult struct {
	Stdout *bytes.Buffer
	Stderr *bytes.Buffer
}

runResult holds the stdout and stderr of a command.

func RunCmd

func RunCmd(ctx context.Context, name string, args ...string) (result RunResult, err error)

RunCmd runs a command within a context, captures its output, provides debug logging, and returns the result. Example:

result, err := RunCmd(ctx, "echo", "hello")
if err != nil {
  return wrapper.Wrap(err)
}
fmt.Println(result.Stdout.String())

Output:

"hello\n"

Jump to

Keyboard shortcuts

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