update

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

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 update implements the gh-style update system: a cached, non-blocking GitHub Releases version check that prints a single stderr notice when a newer release exists, and an explicit, provenance-aware `vibexp update` that checksum-verifies and atomically self-replaces the binary. It never auto-applies and never blocks or fails the wrapped command.

Index

Constants

View Source
const DefaultAPIBase = "https://api.github.com"

DefaultAPIBase is the GitHub API host the release check/update query; tests override it with a local stub.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, w io.Writer, getenv func(string) string, client *http.Client, apiBase, current string, checkOnly bool) error

Apply performs `vibexp update`: it refuses on non-self-updatable installs (printing the correct command), otherwise downloads the matching release asset, verifies it against the release checksums, and atomically replaces the running binary. checkOnly reports availability without applying.

func DefaultStatePath

func DefaultStatePath() (string, error)

DefaultStatePath returns ~/.vibexp/state.json.

func IsNewer

func IsNewer(current, latest string) bool

IsNewer reports whether latest is a strictly higher semver than current.

func Notify

func Notify(ctx context.Context, w io.Writer, getenv func(string) string)

Notify runs the cached background version check and, if a newer release is available, prints a single upgrade notice to w. It never blocks meaningfully (cache hit = no network; a miss is capped at checkTimeout) and never returns an error — the check is strictly advisory. Called once per invocation from Execute after the command has produced its output.

func SaveState

func SaveState(path string, st State) error

SaveState atomically writes the state file (best effort — a failure here must never surface to the user, since the check is advisory).

func ShouldCheck

func ShouldCheck(st State, now time.Time) bool

ShouldCheck reports whether enough time has elapsed to query GitHub again.

func Suppressed

func Suppressed(getenv func(string) string, current string) bool

Suppressed reports whether the background check must not run: opt-out env vars, CI, or a non-release build (dev/source) where there is nothing to compare to.

Types

type Source

type Source int

Source identifies how the running binary was installed, which decides whether `vibexp update` may self-replace it.

const (
	// SourceBinary is a GitHub Releases download (goreleaser). Self-updatable.
	SourceBinary Source = iota
	// SourceBrew is a Homebrew install — upgrade via brew.
	SourceBrew
	// SourceGoInstall is a `go install` / source build — upgrade via go install.
	SourceGoInstall
)

func DetectSource

func DetectSource(getenv func(string) string) Source

DetectSource classifies the install source: the InstallSource ldflag (set by goreleaser/brew) is authoritative; absent it, a path heuristic on the executable distinguishes Homebrew and go-install layouts, defaulting to go-install (a source build is upgraded the same way).

func (Source) SelfUpdatable

func (s Source) SelfUpdatable() bool

SelfUpdatable reports whether `vibexp update` may replace this binary.

func (Source) UpgradeCommand

func (s Source) UpgradeCommand() string

UpgradeCommand returns the correct upgrade instruction for a non-self-updatable source.

type State

type State struct {
	// LastCheck is when the GitHub Releases API was last queried.
	LastCheck time.Time `json:"last_check"`
	// LatestSeen is the most recent release tag observed (e.g. "v1.2.3").
	LatestSeen string `json:"latest_seen,omitempty"`
	// ETag is the release response's ETag, sent as If-None-Match to get cheap
	// 304s that don't count against the unauthenticated rate limit body.
	ETag string `json:"etag,omitempty"`
}

State is the persisted update-check cache (~/.vibexp/state.json). It exists only to rate-limit the network check and remember the last seen release.

func LoadState

func LoadState(path string) State

LoadState reads the state file; a missing or unreadable file yields a zero State (the check simply treats it as "never checked").

Jump to

Keyboard shortcuts

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