util

package
v0.101.5 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DotSlash added in v0.100.0

func DotSlash(path string) string

DotSlash ensures a relative path has a leading ./ needed for CUE loading.

func EnsureNewline

func EnsureNewline(b []byte) []byte

EnsureNewline adds a trailing newline if not already there.

func FindCueMod added in v0.98.0

func FindCueMod(path string) (root string, err error)

FindCueMod returns the root module location containing the cue.mod.

func FindRootLeaf added in v0.98.0

func FindRootLeaf(target string) (root string, leaf string, err error)

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"

func RunCmdA added in v0.101.0

func RunCmdA(ctx context.Context, w io.Writer, name string, args ...string) (result RunResult, err error)

RunCmdA calls RunCmd and always copies the result stderr to w.

func RunCmdW added in v0.100.0

func RunCmdW(ctx context.Context, w io.Writer, name string, args ...string) (result RunResult, err error)

RunCmdW calls RunCmd and copies the result stderr to w if there is an error.

Jump to

Keyboard shortcuts

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