Documentation
¶
Index ¶
- func CaptureExecCmd(command string, args ...string) (string, string, error)
- func CaptureSh(script string) (string, string, error)
- func ChangeDir(newDir string) error
- func CopyFile(src, dst string) error
- func CreateDir(dir string, verbose bool) error
- func CreateFile(filePath string, verbose bool) horus.NotFoundAction
- func CurrentDir() (string, error)
- func DirExist(dirPath string, notFoundAction horus.NotFoundAction, verbose bool) (bool, error)
- func ExecCmd(command string, args ...string) error
- func ExecSh(script string) error
- func FileExist(filePath string, notFoundAction horus.NotFoundAction, verbose bool) (bool, error)
- func FindHome(verbose bool) (string, error)
- func FormatExample(app string, usages ...[]string) string
- func FormatHelp(author, email, desc string) string
- func LineBreaks(withNewline ...bool)
- func ListDirs(directory string) ([]string, error)
- func ListFiles(directory string) ([]string, error)
- func PrintCentered(msg string)
- func ReadDir(path string, verbose bool) ([]os.DirEntry, error)
- func RecallDir() (string, error)
- func RemoveFile(filePath string, verbose bool) horus.NotFoundAction
- func Walk(processor FileProcessor) fs.WalkDirFunc
- type FileProcessor
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureExecCmd ¶
CaptureExecCmd executes the specified command with provided arguments and captures its standard output and error output into separate strings. If an error occurs during execution, it returns a Horus-wrapped error with detailed context.
func ChangeDir ¶
ChangeDir attempts to chdir into newDir. On failure it wraps the os.Chdir error with a fresh Herror, tagging it FS_ERROR and recording the target path.
func CreateDir ¶
CreateDir ensures that the directory at `dir` exists. If `verbose` is true, it prints diagnostic messages before and after checking / creating. Any errors are wrapped and propagated via horus
func CreateFile ¶
func CreateFile(filePath string, verbose bool) horus.NotFoundAction
CreateFile returns a NotFoundAction that attempts to create a file if it doesn't exist. If the file is successfully created, the action returns (true, nil). Otherwise, it returns (false, error) with detailed diagnostic information.
func CurrentDir ¶
CurrentDir returns the base name (last component) of the current directory. It obtains the absolute path of the current directory and then extracts its base name. If an error occurs while determining the absolute path, it returns a wrapped error using Horus.
func DirExist ¶
DirExist checks if a directory exists. If it doesn't, it executes the provided notFoundAction. It returns a tuple: a boolean indicating overall success (either the directory exists or the custom action adequately handled the situation) and an error carrying detailed diagnostic context. The verbose flag enables optional logging.
func ExecCmd ¶
ExecCmd executes the specified command with the provided arguments. It configures the command to forward its output (Stdout and Stderr) to the operating system's standard streams, preserving any color codes. If executing the command fails, ExecCmd returns a wrapped error using Horus.
func ExecSh ¶
ExecSh runs a snippet under /bin/sh -c, forwarding stdout/stderr and wrapping any failure in a Horus Herror.
func FileExist ¶
FileExist checks if filePath exists. If it does, returns (true, nil). If it does not exist and notFoundAction is nil, returns (false, nil). If notFoundAction is non-nil, it’s invoked on absence. Any real I/O error (other than “not exist”) or action-error bubbles up.
Example (AutoCreate) ¶
create := func(path string) (bool, error) {
f, err := os.Create(path)
if err != nil {
return false, err
}
defer f.Close()
_, _ = f.WriteString("# default\n")
return true, nil
}
exists, _ := FileExist("example.conf", create, false)
fmt.Println(exists)
Output: true
Example (Basic) ¶
exists, _ := FileExist("no-such-file", nil, false)
fmt.Println(exists)
Output: false
func FindHome ¶
FindHome attempts to retrieve the current user's home directory. If verbose is true it prints diagnostics; otherwise it's silent. On error it returns a categorized *Herror.
func FormatExample ¶
FormatExample builds a multi‐line example block each usage is a slice of "tokens": [ command, flagOrArg, flagOrArg, ... ].
func FormatHelp ¶
FormatHelp produces the "help" header + description
func LineBreaks ¶
func LineBreaks(withNewline ...bool)
LineBreaks prints a decorative line break consisting of 100 grey "=" symbols. If the optional withNewline argument is true, it will also print a trailing newline. Default behavior (no args or withNewline[0]==false) is to emit no final newline.
func ListFiles ¶
ListFiles returns a slice of names for all regular files in the provided directory. If the directory cannot be read, it returns a wrapped error using horus.
func PrintCentered ¶
func PrintCentered(msg string)
PrintCentered prints msg centered in a 100-column width, surrounding it with “=” fills and one space padding on each side.
func ReadDir ¶
ReadDir reads the directory named by path and returns a list of directory entries. If verbose is true, it prints diagnostic messages before and after the read.
func RecallDir ¶
RecallDir returns the current working directory. On failure, it returns a wrapped error with diagnostic details using Horus.
func RemoveFile ¶
func RemoveFile(filePath string, verbose bool) horus.NotFoundAction
RemoveFile returns a NotFoundAction that attempts to delete a file if it exists. If the file is successfully removed (or already missing), it returns (true, nil). Otherwise, it returns (false, error) with detailed diagnostic information.
func Walk ¶
func Walk(processor FileProcessor) fs.WalkDirFunc
Walk returns an fs.WalkDirFunc that applies the given processor function to each non-directory file. Hidden files are ignored, and any encountered errors are wrapped and propagated using Horus.
Types ¶
type FileProcessor ¶
type FileProcessor func(string)
FileProcessor defines the type for a file processing function.