Documentation
¶
Index ¶
- func Cd(dir string)
- func Contains(file, substr string) bool
- func Copy(src, dst string)
- func Cwd() string
- func Delete(path string)
- func DosToUnix(glob string)
- func EnsureDir(dir string) string
- func Exists(file string) bool
- func FindAll(glob string) []string
- func FindParent(dir string, glob string) string
- func Fingerprint(globs ...string) string
- func HumanizeBytes[T int | int64](size T) any
- func InDir(dir string, run func())
- func InTempDir(fn func())
- func IsDir(dir string) bool
- func IsRegular(name string) bool
- func JoinPaths(paths ...string) string
- func LogWorkdir()
- func Ls(dir string) string
- func Read(file string) string
- func Require(file string)
- func Sha256Hash(file string) string
- func WithTempDir(fn func(dir string))
- func Write(path, contents string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cd ¶
func Cd(dir string)
Cd changes the current working directory to the provided relative or absolute directory
func Copy ¶ added in v0.1.0
func Copy(src, dst string)
Copy copies the source file to the destination file, preserving permissions
func Delete ¶
func Delete(path string)
Delete removes the given file or directory recursively. As a safety measure, it verifies the path is under RootDir before deletion to prevent accidental deletion of files outside the project. Panics if the path is outside RootDir.
func DosToUnix ¶ added in v0.1.0
func DosToUnix(glob string)
DosToUnix converts all files matching the glob pattern from DOS/Windows line endings (CRLF) to Unix line endings (LF). Files that don't contain CRLF are skipped. Preserves file permissions.
func EnsureDir ¶
EnsureDir checks if the directory exists. create if not, including any subdirectories needed and returns the absolute path to the directory
func Exists ¶
Exists indicates a file of any type (regular, directory, symlink, etc.) exists and is readable
func FindAll ¶
FindAll returns all files matching the given glob pattern. Uses the doublestar library, supporting "**" for recursive directory matching.
Example:
FindAll("**/*.go") // all Go files recursively
FindAll("cmd/**/main.go") // main.go files under cmd/
func FindParent ¶
FindParent traverses up the directory tree from dir, looking for a file matching the glob pattern. Returns the first match found, or an empty string if none found. Useful for finding config files like .binny.yaml or .git in parent directories.
func Fingerprint ¶
Fingerprint computes an MD5 hash of all files matching the given glob patterns. Files are sorted before hashing to ensure a stable, reproducible result. Useful for cache invalidation or detecting changes in a set of files.
Supports doublestar glob syntax (e.g., "**/*.go" for recursive matching).
func HumanizeBytes ¶ added in v0.1.0
HumanizeBytes converts a byte count to a human-readable string with appropriate units (KB, MB, GB, TB). Returns just the number for sizes less than 1KB.
func InDir ¶
func InDir(dir string, run func())
InDir executes the given function in the provided directory, returning to the current working directory upon completion
func InTempDir ¶
func InTempDir(fn func())
InTempDir executes with the current working directory in a new temporary directory, restoring cwd and removing all contents of the temp directory upon completion
func IsRegular ¶
IsRegular indicates the provided file exists and is a regular file, not a directory or symlink
func Ls ¶
Ls returns a formatted directory listing similar to "ls -l", showing file permissions, human-readable size, and filename for each entry in the directory.
func Sha256Hash ¶
Sha256Hash computes the SHA-256 hash of the specified file and returns it as a lowercase hexadecimal string. Panics if the file cannot be read.
func WithTempDir ¶
func WithTempDir(fn func(dir string))
WithTempDir creates a temporary directory and passes it to the provided function. The directory is automatically deleted when the function returns, unless config.Cleanup is false (which happens in Debug mode or CI environments for debugging purposes).
Types ¶
This section is empty.