Documentation
¶
Index ¶
- func CheckWritePermission(binaryPath string) error
- func IsHomebrew(binaryPath string) bool
- type Cache
- type Checker
- func (c *Checker) Check(ctx context.Context) (*Result, error)
- func (c *Checker) CheckWithCooldown(ctx context.Context, cooldown time.Duration) (*Result, error)
- func (c *Checker) FormatCheckOutput(r *Result) string
- func (c *Checker) FormatNotification(r *Result) string
- func (c *Checker) IsDev() bool
- func (c *Checker) SetAPIURL(url string)
- type ProgressFunc
- type ReleaseAsset
- type Result
- type Updater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckWritePermission ¶
CheckWritePermission verifies the binary's directory is writable before downloading. Returns nil if writable, or an error with an actionable message.
func IsHomebrew ¶
IsHomebrew returns true if the resolved binary path indicates Homebrew management. Checks both Intel (/usr/local/Caskroom/, /usr/local/Cellar/) and Apple Silicon (/opt/homebrew/Caskroom/, /opt/homebrew/Cellar/) paths.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache manages the update check cooldown file.
func (*Cache) ShouldCheck ¶
ShouldCheck returns true if the cache is missing, corrupt, or the cooldown has expired. A true return means the caller should query the GitHub API.
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker queries GitHub Releases for the latest version.
func NewChecker ¶
NewChecker creates a Checker for the given current version. If currentVersion cannot be parsed as semver (e.g. "dev"), IsDev() returns true and all checks are no-ops.
func (*Checker) Check ¶
Check queries the GitHub Releases API and compares the latest tag against the current version. It does NOT read or write the cache — use CheckWithCooldown for cache-gated checks.
func (*Checker) CheckWithCooldown ¶
CheckWithCooldown is the background-safe entry point. It respects the dev guard and 24h cooldown cache before hitting the GitHub API.
func (*Checker) FormatCheckOutput ¶
FormatCheckOutput returns the --check-update formatted output. Returns empty string if result is nil.
func (*Checker) FormatNotification ¶
FormatNotification returns the two-line gh CLI style notification. Returns empty string if no update is available or result is nil.
type ProgressFunc ¶
type ProgressFunc func(msg string)
ProgressFunc is called with status messages during the update process. All messages go to stderr. The caller provides the callback.
type ReleaseAsset ¶
type ReleaseAsset struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
}
ReleaseAsset represents a downloadable file attached to a GitHub release.
type Result ¶
type Result struct {
UpdateAvailable bool `json:"update_available"`
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
ReleaseURL string `json:"release_url"`
Assets []ReleaseAsset `json:"assets,omitempty"`
}
Result holds the outcome of a version check.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater downloads, verifies, and installs binary updates from GitHub Releases.
func NewUpdater ¶
NewUpdater creates an Updater that uses the given Checker for version lookups.
func (*Updater) Update ¶
Update performs the full self-update sequence:
- Check for latest version via GitHub API
- Verify not already up to date
- Find platform-specific archive and checksums in release assets
- Download checksums.txt, parse expected hash
- Download platform archive, verify SHA256
- Extract binary from tar.gz to temp file
- Rename current binary to .bak (rollback preservation)
- Rename new binary to target path (atomic replace)
On any failure after step 7, the .bak is restored. binaryPath is the resolved path to the current executable.