util

package
v0.39.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CWD = func() string {
	dir, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	return dir + "/"
}()

CWD for computing RelPathCWD().

We do this once at init time, but we also make it public so we can update it with flags if necessary.

Functions

func Capture

func Capture(log ui.Logger, args ...string) ([]byte, error)

Capture runs a command, returning combined stdout and stderr.

func CaptureInDir added in v0.2.29

func CaptureInDir(log ui.Logger, dir string, args ...string) ([]byte, error)

CaptureInDir runs a command in the given dir, returning combined stdout and stderr.

func Command

func Command(log *ui.Task, args ...string) (*exec.Cmd, *bytes.Buffer)

Command constructs a new exec.Cmd with logging configured.

Returns the command, and a *bytes.Buffer containing the combined stdout and stderr of the execution

func Ext

func Ext(path string) string

Ext returns the full extension of a path.

func GlobOne

func GlobOne(glob string) (string, error)

GlobOne globs exactly one file.

func Hash

func Hash(values ...interface{}) string

Hash computes a (probably) unique hash of "values".

func RealPath

func RealPath(path string) string

RealPath converts a path into its absolute, symlink-expanded form.

func RelPathCWD

func RelPathCWD(path string) string

RelPathCWD returns "path" relative to the current working directory.

func RelPathsCWD

func RelPathsCWD(paths []string) []string

RelPathsCWD returns "paths" relative to the current working directory.

func ResolveSymlinks(path string) (links []string, err error)

ResolveSymlinks returns all symlinks in a chain, including the final file, as absolute paths.

func Run

func Run(log *ui.Task, args ...string) error

Run a command, outputting to stdout and stderr.

func RunInDir

func RunInDir(log *ui.Task, dir string, args ...string) error

RunInDir runs a command in the given directory.

func Sha256LocalFile added in v0.29.0

func Sha256LocalFile(path string) (string, error)

Sha256LocalFile Utility function to hash a downloaded file.

Types

type CommandRunner added in v0.23.2

type CommandRunner interface {
	// RunInDir runs a command in the given directory.
	RunInDir(log *ui.Task, dir string, args ...string) error
}

CommandRunner abstracts how we run command in a given directory

type FileLock

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

FileLock abstracts away the file locking mechanism. One FileLock corresponds to a one file on disk. This does not support multi-threading. Use only from within one go routine.

func NewLock

func NewLock(file string, checkInterval time.Duration) *FileLock

NewLock creates a new file lock.

func (*FileLock) Acquire

func (l *FileLock) Acquire(ctx context.Context, log ui.Logger) error

Acquire takes the lock. For every Acquire, Release needs to be called later. Returns immediately if this process already holds the lock.

func (*FileLock) Release

func (l *FileLock) Release(log ui.Logger)

Release releases the lock. If there is an error while releasing, the error is logged

type FilePatcher

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

FilePatcher is used to update or set lines in a text file, separated by given start and end line markers

func NewFilePatcher

func NewFilePatcher(start, end string) *FilePatcher

NewFilePatcher creates a new FilePatcher

func (*FilePatcher) Patch

func (fp *FilePatcher) Patch(fileName, content string) (bool, error)

Patch updates the contents in a file.

type RealCommandRunner added in v0.23.2

type RealCommandRunner struct{}

RealCommandRunner actually calls command

func (*RealCommandRunner) RunInDir added in v0.23.2

func (g *RealCommandRunner) RunInDir(task *ui.Task, dir string, commands ...string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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