util

package
v0.106.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 14 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 Executable added in v0.104.2

func Executable() (string, error)

Executable returns the fully qualified path to the "holos" executable by searching through the PATH. If the current executable starts with "holos", it returns that path, otherwise it searches for "holos" in PATH.

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)

FindRootLeaf returns the root path containing the cue.mod and the leaf path relative to the root for the given target path. FindRootLeaf calls filepath.Clean on the returned paths.

func MakeCopyFunc added in v0.104.2

func MakeCopyFunc(ctx context.Context, efs embed.FS, dest string) fs.WalkDirFunc

MakeCopyFunc returns a fs.WalkDirFunc copying from embed.FS efs to dest. Useful for embedded test case fixtures.

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 RunCmdFunc added in v0.104.2

func RunCmdFunc(ctx context.Context, w io.Writer, name string, args []string, preRun func(*exec.Cmd) error) (result RunResult, err error)

RunCmdFunc runs a command within a context, captures its output, provides debug logging, and returns the result. preRun is called after configuration and before exec.Cmd.Run.

RunCmdFunc copies stderr to w when an error occurs. The copy is safe for concurrent use with other functions in this package.

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