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
- func Apply(ctx context.Context, w io.Writer, getenv func(string) string, ...) error
- func DefaultStatePath() (string, error)
- func IsNewer(current, latest string) bool
- func Notify(ctx context.Context, w io.Writer, getenv func(string) string)
- func SaveState(path string, st State) error
- func ShouldCheck(st State, now time.Time) bool
- func Suppressed(getenv func(string) string, current string) bool
- type Source
- type State
Constants ¶
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 ¶
DefaultStatePath returns ~/.vibexp/state.json.
func Notify ¶
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 ¶
SaveState atomically writes the state file (best effort — a failure here must never surface to the user, since the check is advisory).
func ShouldCheck ¶
ShouldCheck reports whether enough time has elapsed to query GitHub again.
Types ¶
type Source ¶
type Source int
Source identifies how the running binary was installed, which decides whether `vibexp update` may self-replace it.
func DetectSource ¶
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 ¶
SelfUpdatable reports whether `vibexp update` may replace this binary.
func (Source) UpgradeCommand ¶
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.