util

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandWithResult

func CommandWithResult(ctx context.Context, logger *log.Logger, command *Command) (output string, err error)

CommandWithResult executes a command and returns its output, while printing the same output to the given logger.

func FilterArgs added in v0.6.0

func FilterArgs(args []string, filter []string, ignore bool) (filtered []string)

FilterArgs filters the arguments by either ignoring/allowing them in the result.

func FilterArgsKeep added in v0.6.0

func FilterArgsKeep(args []string, filter []string) (filtered []string)

FilterArgsKeep filters the given argument list and only returns arguments defined present in "filter".

func FilterArgsRemove added in v0.6.0

func FilterArgsRemove(args []string, filter []string) (filtered []string)

FilterArgsRemove filters the given argument list and returns arguments where "filter" entries are removed.

func Flags added in v0.6.0

func Flags(cmd any) (args []string)

Flags returns a list of `long` flags bound on the command or nil.

func FormatToGoObject added in v0.6.0

func FormatToGoObject(object any) string

FormatToGoObject formats the given object to equivalent Go code.

func Pretty added in v0.6.0

func Pretty(object any) string

Pretty pretty prints the given object to a string.

func PrettyPrint added in v0.6.0

func PrettyPrint(object any)

PrettyPrint pretty prints the given object to STDOUT.

func Set added in v1.0.0

func Set[T comparable](s []T) map[T]bool

Set creates a set from a slice.

func UniqueDirectory added in v0.6.0

func UniqueDirectory(path string) (uniquePath string, err error)

UniqueDirectory creates a unique directory from the given path.

func UniqueName added in v0.6.0

func UniqueName(name string, existsFunction func(candidate string) (bool, error)) (uniqueName string, err error)

UniqueName creates an unique name.

Types

type Command

type Command struct {
	// Command holds the command with its optional arguments.
	Command []string
	// Stdin holds a string which is passed on as STDIN.
	Stdin string

	// Directory defines the directory the execution should run in, without changing the working directory of the caller.
	Directory string
	// Env overwrites the environment variables of the executed command.
	Env map[string]string
}

Command defines a command that should be executed.

type Parallel added in v0.6.0

type Parallel struct {
	// contains filtered or unexported fields
}

Parallel holds a buffered channel for limiting parallel executions.

func NewParallel added in v0.6.0

func NewParallel(maxWorkers uint) *Parallel

NewParallel returns a Parallel execution helper.

func (*Parallel) Execute added in v0.6.0

func (p *Parallel) Execute(f func())

Execute runs the given function while checking for a execution limit.

func (*Parallel) Wait added in v0.6.0

func (p *Parallel) Wait()

Wait waits until all executions are done.

Jump to

Keyboard shortcuts

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