Documentation
¶
Overview ¶
Package update provides self-update detection and installation method logic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentBinaryPath ¶
CurrentBinaryPath returns the absolute path to the running executable, resolving any symlinks.
func FetchLatest ¶
FetchLatest is an exported wrapper around fetchLatestVersion. If apiURL is empty it uses the default GitHub releases URL.
func IsNewer ¶
IsNewer reports whether latest is a higher semver than current. Returns false when either value is not valid semver (e.g. "dev").
func SelfUpdate ¶
SelfUpdate downloads the release archive for newVersion, verifies its checksum, extracts the binary, and atomically replaces binaryPath.
baseURL is a template with {tag} and {name} placeholders. Pass an empty string to use the default GitHub releases URL.
Types ¶
type Cache ¶
type Cache struct {
LatestVersion string `json:"latest_version"`
CheckedAt time.Time `json:"checked_at"`
NotifiedAt time.Time `json:"notified_at,omitempty"`
NotifiedVersion string `json:"notified_version,omitempty"`
}
Cache holds the persisted update-check state between CLI runs.
type CheckResult ¶
type CheckResult struct {
// ShouldNotify is true when the user should be told about a new version.
ShouldNotify bool
// LatestVersion is the newest version available (set when ShouldNotify is true).
LatestVersion string
// RefreshDone is closed when the background cache refresh completes.
// Nil if no refresh was needed. Callers can select on this to wait.
RefreshDone <-chan struct{}
}
CheckResult holds the outcome of CheckForUpdate.
func CheckForUpdate ¶
func CheckForUpdate(currentVersion, configDir, apiURL string) CheckResult
CheckForUpdate implements the cache-then-notify pattern:
- Read cache synchronously (fast path).
- If cache is stale, spawn a background goroutine to refresh it for the NEXT run.
- Compare cached latest vs currentVersion.
- Apply notification-suppression rules.
- If notifying, update the cache and return CheckResult with ShouldNotify=true.
If the cache is stale, RefreshDone will be a non-nil channel that closes when the background refresh completes. Callers can optionally wait on it to ensure the cache is populated before the process exits.
type InstallMethod ¶
type InstallMethod int
InstallMethod describes how the binary was installed.
const ( // DirectDownload means the binary was downloaded directly (e.g. from GitHub Releases). DirectDownload InstallMethod = iota // Homebrew means the binary was installed via Homebrew. Homebrew // GoInstall means the binary was installed via go install. GoInstall )
func DetectInstallMethod ¶
func DetectInstallMethod(binaryPath string) InstallMethod
DetectInstallMethod returns the InstallMethod for the given binary path. Use filepath.ToSlash for cross-platform path comparison.
func (InstallMethod) String ¶
func (m InstallMethod) String() string
String returns the human-readable name of the install method.