notify

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package notify performs a passive, never-blocking "you're behind" check for a Go CLI and prints a one-line hint when a newer GitHub release exists.

The hint is served from a small cache file - an instant disk read, never the network - so it adds no latency to the command. When that cache is stale, a background goroutine refreshes it; the refresh is never awaited, so it overlaps the caller's work and is abandoned at process exit if still running. The flush re-reads the cache, so a refresh that finishes while the command runs is shown that same run; otherwise its result appears on the next invocation. A tool describes itself with a brew.Config - the same value its self-update uses - calls Check before dispatching its command, and invokes the returned flush function after:

flush := notify.Check(brew.Config{
	Info:    clive.Info{Module: "github.com/me/myapp"},
	Formula: "myapp",
})
defer flush()

The check is silenced by the per-tool kill switch MYAPP_NO_UPDATE_CHECK (derived from the binary name) and by a non-terminal stderr, and the network is touched at most once per cooldown.

By default "latest" is the highest semver tag in the tool's GitHub repository. A tool whose releases are not readable GitHub tags - a private repo, or one distributed from an artifact bucket - overrides the lookup with WithLatestFunc while keeping the same cache, cooldown, and output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(cfg brew.Config, opts ...Option) func()

Check serves an "update available" hint from the per-tool cache and, when that cache is stale, refreshes it in the background for the next invocation. It never blocks and never touches the network on the calling path. cfg describes the tool: its binary name forms the kill-switch env var, the cache namespace, and the `<binary> update` command, and its display name opens the message.

The returned function prints the hint; the caller invokes it after its command completes, so the hint follows the command's own output. It is a no-op when no update is pending, when the check is disabled, or when stderr is not a terminal.

Types

type LatestFunc added in v0.0.10

type LatestFunc func(ctx context.Context) (string, error)

LatestFunc reports the latest released version of the tool, such as "v1.2.3" (a leading "v" is optional). It is called only on a stale-cache refresh, off the calling path, and bounded by the same lookupTimeout as the default check.

type Option

type Option func(*checker)

Option configures a Check. The defaults target a real run; the seams exist for testing and for callers that supply their own HTTP client or accent.

func WithCacheDir

func WithCacheDir(dir string) Option

WithCacheDir overrides the directory holding the cache file.

func WithColor added in v0.0.9

func WithColor(c color.Color) Option

WithColor overrides the accent colour of the update message. It defaults to the orange lipgloss.Color(updateColor).

func WithCurrentVersion

func WithCurrentVersion(v string) Option

WithCurrentVersion overrides the running version compared against the latest tag. It defaults to clive.Current.

func WithLatestFunc added in v0.0.10

func WithLatestFunc(fn LatestFunc) Option

WithLatestFunc overrides how a refresh discovers the latest version. By default the latest version is the highest semver tag in the tool's GitHub repository (clive.Info.LatestTag); a tool whose releases are not published as readable GitHub tags - e.g. a private repo distributed from an artifact bucket - supplies its own lookup here.

func WithTransport

func WithTransport(rt http.RoundTripper) Option

WithTransport sets the HTTP transport, the seam tests use to serve canned tag payloads without touching the network.

Jump to

Keyboard shortcuts

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