updatecheck

package
v0.6.14 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package updatecheck implements an unobtrusive "new version available" notifier for the Mercury CLI, modelled after gh/flyctl/deno.

The check runs in a background goroutine kicked off at the start of a CLI invocation. At the end of the invocation the caller joins the goroutine with a short deadline via Notify; if a strictly-newer release is known, a short banner is written to the provided writer (typically os.Stderr). A local cache keeps most invocations off the network entirely.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchLatest

func FetchLatest(ctx context.Context) (string, error)

FetchLatest is an on-demand, uncached version lookup. Used by `mercury upgrade` to decide whether there's anything to install.

Types

type Checker

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

Checker is the handle returned by Start. It is safe to call Notify at most once per Checker.

func Start

func Start(ctx context.Context, opts Options) *Checker

Start kicks off a background update check and returns immediately. The returned *Checker is never nil; Notify on a suppressed Checker is a no-op.

func (*Checker) Notify

func (c *Checker) Notify(w io.Writer)

Notify waits up to ~200ms for the background check to finish and, if a strictly-newer release is known, writes a short banner to w. It never returns an error — update notifications must never disrupt the command.

type Options

type Options struct {
	CurrentVersion string
	Args           []string
	VersionURL     string
	CachePath      string
	CacheTTL       time.Duration
	HTTPClient     *http.Client
	Now            func() time.Time
	// LookupEnv overrides os.LookupEnv, for tests.
	LookupEnv func(string) (string, bool)
}

Options configures a Checker. Fields left at their zero value pick reasonable defaults; tests can override any of them.

Jump to

Keyboard shortcuts

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