updatecheck

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 14 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package updatecheck reports whether a newer GitHub release of a CLI exists and how to upgrade it via the package manager that installed it. It never touches the binary — the actual upgrade is delegated to the package manager (see ADR-0005).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheFile added in v0.14.0

func CacheFile(app string) string

CacheFile is the conventional update-check cache path for app — the hint writes it and WhatsNewCommand reads it as its offline fallback. "" if the user cache dir is unavailable.

func WhatsNewCommand added in v0.13.0

func WhatsNewCommand(cfg WhatsNewConfig) *cobra.Command

WhatsNewCommand returns a `whatsnew` cobra command that renders the release notes for every version newer than the running build, glamour-rendered. See forge ADR-0012.

Types

type Checker

type Checker struct {
	Repo    string       // "owner/name"
	BaseURL string       // "" → https://api.github.com
	Client  *http.Client // nil → a client with a 5s timeout
}

Checker queries a GitHub repo's latest release.

func (Checker) CheckNewer

func (c Checker) CheckNewer(ctx context.Context, current string) (latest string, newer bool, err error)

CheckNewer returns the latest release tag for the repo and whether it is newer than current.

type Hinter

type Hinter struct {
	Repo      string           // "owner/name"
	Bin       string           // binary name: the hint label and brew/mise/scoop command
	Module    string           // `go install` target path (used only when go-installed)
	Current   string           // current version
	CacheFile string           // "" → always fetch (no cache)
	OptOutEnv string           // env var that disables the hint when set to "false"
	Skip      func() bool      // optional app gate; hint skipped when it returns true (run-time)
	BaseURL   string           // "" → https://api.github.com (test seam)
	Client    *http.Client     // nil → default
	Now       func() time.Time // nil → time.Now (test seam)
}

Hinter prints a one-line upgrade hint when a newer release exists, fetching at most once per 24h (when CacheFile is set). Every error is swallowed — the hint must never break a normal run.

func (Hinter) PostRun added in v0.14.0

func (h Hinter) PostRun() func(*cobra.Command, []string) error

PostRun returns a cobra PersistentPostRunE that prints the upgrade hint after each command, unless this is a dev build (Current == "dev"), OptOutEnv is set to "false", or the optional Skip gate returns true. It bounds the check to hintTimeout and swallows errors, so every tool wires the hint identically: root.PersistentPostRunE = Hinter{…}.PostRun().

func (Hinter) Print

func (h Hinter) Print(ctx context.Context, w io.Writer)

Print writes a multi-line upgrade hint to w when a newer release exists. Errors are swallowed.

type InstallMethod

type InstallMethod int

InstallMethod is how a binary was installed, inferred from its path.

const (
	Unknown InstallMethod = iota
	Homebrew
	Mise
	Scoop
	GoInstall
)

func DetectInstall

func DetectInstall() InstallMethod

DetectInstall infers how the running executable was installed by resolving its real path and matching known package-manager locations.

func (InstallMethod) UpgradeCommand

func (m InstallMethod) UpgradeCommand(bin, module string) string

UpgradeCommand returns the command to upgrade bin via this install method, or "" for Unknown (callers fall back to a generic message). module is the `go install` target path, used only for GoInstall.

type WhatsNewConfig added in v0.13.0

type WhatsNewConfig struct {
	Repo      string           // "owner/name"
	Current   string           // running version
	CacheFile string           // offline fallback source ("" → no fallback)
	Changelog string           // embedded changelog markdown, the last offline fallback ("" → none)
	BaseURL   string           // "" → https://api.github.com
	Client    *http.Client     // nil → default
	Now       func() time.Time // nil → time.Now
}

WhatsNewConfig parameterises WhatsNewCommand for one tool. Repo and Current are required; CacheFile enables the offline fallback, and BaseURL/Client/Now are test seams.

Jump to

Keyboard shortcuts

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