checkpoint

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package checkpoint provides a small file-based cache for resumable, task-oriented CLIs: Recover loads a previously Commit-ed value by key, or returns the supplied default if no cache is configured or the value is missing/unreadable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commit

func Commit[T any](key string, val T) error

Commit persists val under key in the default Cache (see Default/SetDefault). It is a no-op if no cache directory is configured.

func Recover

func Recover[T any](key string, def T) T

Recover loads the value previously stored under key by Commit, using the default Cache (see Default/SetDefault). It returns def if no cache directory is configured, the key is unknown, or the cached value cannot be read or decoded (in the latter cases, the optional WithWarn callback is invoked).

func SetDefault

func SetDefault(c *Cache)

SetDefault replaces the package-level Cache used by Recover/Commit.

Types

type Cache

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

Cache is a directory-backed, SHA1-keyed YAML cache. The zero value and a nil *Cache are both safe to use: Recover returns the default value and Commit is a no-op.

func Default

func Default() *Cache

Default returns the package-level Cache used by Recover/Commit.

func New

func New(dir string, opts ...Option) *Cache

New returns a Cache rooted at dir. If dir == "", the returned Cache is a no-op: Recover always returns the default value, Commit always returns nil.

type Option

type Option func(*Cache)

Option configures a Cache.

func WithWarn

func WithWarn(f func(format string, args ...any)) Option

WithWarn registers a callback invoked when Recover cannot read or decode a cached value, so the caller can surface this to the user (e.g. via chalk.Printf).

Jump to

Keyboard shortcuts

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