file

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

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 Contains

func Contains(file, substr string) bool

Contains indicates the given file contains the provided substring

func Copy added in v0.1.0

func Copy(src, dst string)

Copy copies the source file to the destination file, preserving permissions

func Cwd

func Cwd() string

Cwd returns the current working directory

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

func EnsureDir(dir string) string

EnsureDir checks if the directory exists. create if not, including any subdirectories needed and returns the absolute path to the directory

func Exists

func Exists(file string) bool

Exists indicates a file of any type (regular, directory, symlink, etc.) exists and is readable

func FindAll

func FindAll(glob string) []string

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

func FindParent(dir string, glob string) string

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

func Fingerprint(globs ...string) string

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

func HumanizeBytes[T int | int64](size T) any

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 IsDir

func IsDir(dir string) bool

IsDir indicates the provided directory exists and is a directory

func IsRegular

func IsRegular(name string) bool

IsRegular indicates the provided file exists and is a regular file, not a directory or symlink

func JoinPaths

func JoinPaths(paths ...string) string

JoinPaths joins paths together using an OS-appropriate separator

func LogWorkdir

func LogWorkdir()

LogWorkdir logs an ls of the current working directory

func Ls

func Ls(dir string) string

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 Read

func Read(file string) string

Read reads the file and returns the contents as a string

func Require

func Require(file string)

Require panics if the provided file does not exist

func Sha256Hash

func Sha256Hash(file string) string

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).

func Write

func Write(path, contents string)

Write writes the provided contents to a file

Types

This section is empty.

Jump to

Keyboard shortcuts

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