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 ¶
- Variables
- func CacheFilePath() (string, error)
- func FetchLatestVersion() (string, error)
- func FormatNotice(current, latest string) string
- func RunBackgroundCheck(currentVersion string, interval time.Duration) <-chan string
- func SaveState(s *State) error
- func ShouldCheck(s *State, interval time.Duration) bool
- type State
Constants ¶
This section is empty.
Variables ¶
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 ¶
CacheFilePath returns the path to the update-check cache file.
func FetchLatestVersion ¶
FetchLatestVersion queries the GitHub releases API and returns the newest stable version string (without a leading "v"). Drafts and prereleases are skipped.
func FormatNotice ¶
FormatNotice returns a single-line update notice suitable for printing to stderr. Kept short to minimise noise for AI agents and scripts.
func RunBackgroundCheck ¶
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:
}