Documentation
¶
Overview ¶
Package update powers the passive update nudge (CachedCheck) and the `ana update` self-update verb (SelfUpdate). All logic sits behind injected deps so cmd/ana stays thin wiring.
Stdlib-only; mirrors goreleaser's archive layout and install.sh's URL template.
Index ¶
- func CachePath(env func(string) string) (string, error)
- func CachedCheck(ctx context.Context, deps CacheDeps, ttl time.Duration, currentVersion string) (string, bool, error)
- func CmpSemver(a, b string) int
- func LatestRelease(ctx context.Context, client HTTPDoer) (string, error)
- func ParseInterval(s *string) (time.Duration, bool)
- func SelfUpdate(ctx context.Context, deps Deps, currentVersion string, w io.Writer, ...) error
- type CacheDeps
- type Deps
- type HTTPDoer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CachePath ¶
CachePath resolves $XDG_CACHE_HOME/ana/update-check.json with a $HOME/.cache/... fallback; both unset → error so callers skip the check.
func CachedCheck ¶
func CachedCheck(ctx context.Context, deps CacheDeps, ttl time.Duration, currentVersion string) (string, bool, error)
CachedCheck returns the newest observed release tag plus a notify flag that is true only when currentVersion is older than that tag. When the cache is fresh (age < ttl) no HTTP call is made. A stale or missing cache triggers a LatestRelease call and an atomic cache rewrite. Any error short-circuits to (_, false, err); callers ignore the error since the nudge is best-effort.
func CmpSemver ¶
CmpSemver returns -1/0/+1 comparing two three-int semver strings. Accepts optional leading `v` and an optional `-prerelease` suffix. Prerelease versions sort below their non-prerelease counterparts at the same X.Y.Z (so goreleaser's `prerelease: auto` beta→stable path notifies correctly). Malformed input on either side returns 0 — a bad tag must never trigger a nudge.
func LatestRelease ¶
LatestRelease returns the `tag_name` from GitHub's /releases/latest.
func ParseInterval ¶
ParseInterval interprets the Config.UpdateCheckInterval pointer: nil → (4h, true). "0" or "disable" → (0, false). Any time.ParseDuration-friendly string → (d, true). A malformed duration silently falls back to the default — we never want a bad config value to block the user's verb.
func SelfUpdate ¶
func SelfUpdate(ctx context.Context, deps Deps, currentVersion string, w io.Writer, jsonOut bool) error
SelfUpdate runs the full self-update flow: resolve latest, compare, skip if already current, else download + verify + extract + atomic replace. jsonOut selects a single-object JSON summary on w; otherwise plain-text progress is written line by line. "Already up to date" is success (nil error).