update

package
v0.1.9 Latest Latest
Warning

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

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

Documentation

Overview

Package update implements a non-blocking background version check for the Saber CLI. It caches the result in ~/.saber/update-check.json and only hits the GitHub releases API at most once per check interval (default 24h).

Index

Constants

This section is empty.

Variables

View Source
var ReleasesURL = "https://api.github.com/repos/saberapp/cli/releases?per_page=20"

ReleasesURL is the GitHub API endpoint queried for new releases. It is a variable (not a constant) so that tests can point it at an httptest server.

Functions

func CacheFilePath

func CacheFilePath() (string, error)

CacheFilePath returns the path to the update-check cache file.

func FetchLatestVersion

func FetchLatestVersion() (string, error)

FetchLatestVersion queries the GitHub releases API and returns the newest stable version string (without a leading "v"). Drafts and prereleases are skipped.

func FormatNotice

func FormatNotice(current, latest string) string

FormatNotice returns a single-line update notice suitable for printing to stderr. Kept short to minimise noise for AI agents and scripts.

func RunBackgroundCheck

func RunBackgroundCheck(currentVersion string, interval time.Duration) <-chan string

RunBackgroundCheck starts a non-blocking version check. It returns a channel that will receive at most one message (the update notice) if a newer version is available. The channel is closed when the check completes or is skipped.

The caller should do a non-blocking read on the returned channel after the main command finishes:

select {
case msg := <-ch:
    if msg != "" { fmt.Fprintln(os.Stderr, msg) }
default:
}

func SaveState

func SaveState(s *State) error

SaveState atomically writes the cache file (write tmp + rename).

func ShouldCheck

func ShouldCheck(s *State, interval time.Duration) bool

ShouldCheck returns true when the cached state is stale (or empty).

Types

type State

type State struct {
	LatestVersion string    `json:"latestVersion"`
	CheckedAt     time.Time `json:"checkedAt"`
}

State is persisted to ~/.saber/update-check.json between runs.

func LoadState

func LoadState() *State

LoadState reads the cached update state. Returns a zero-value State (not an error) when the file is missing or corrupt, so callers never need to handle "first run" specially.

Jump to

Keyboard shortcuts

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