util

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HumanTimeElapsedSince

func HumanTimeElapsedSince(d time.Duration) string

humanTimeElapsedSince returns a human-friendly "in the past" representation of the given duration.

func InputFromEditor

func InputFromEditor(placeholder string, pattern string, content string) (string, error)

InputFromEditor retrieves user input by opening an editor (one specified by $EDITOR or 'vim' if $EDITOR is not set) on a temporary file. Once the editor closes, the contents of the file are read and the file is deleted. If the contents of the file exactly match the value of placeholder (no edits to the file were made), then an empty string is returned. Otherwise, the contents are returned. Example patten: message.*.md

func ReadFileContents

func ReadFileContents(file string) (string, error)

ReadFileContents returns the string contents of the given file.

func SetStructDefaults

func SetStructDefaults(data any) bool

SetStructDefaultValues checks for any nil ptr fields within the passed struct, and sets the values of those fields to the value that is defined by their "default" struct tag. Handles setting string, int, and bool values. Returns whether any changes were made to the struct.

func ShortPath

func ShortPath(path string) string

ShortPath replaces the user's home directory with ~.

func TryExtractJSONObject

func TryExtractJSONObject(s string, target any) error

TryExtractJSONObject finds the first '{' in s and the first '}' after it, then unmarshals the enclosed substring into target. Useful for extracting a JSON object from an LLM response that may contain surrounding text or markdown fences. Does not handle nested objects

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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