Documentation
¶
Index ¶
- func ArchiveName(version string) string
- func CheckAndCache(currentVersion string)
- func CompareVersions(current, latest string) bool
- func DownloadAsset(url, destDir string) (string, error)
- func ExtractBinary(archivePath, destDir string) (string, error)
- func FindAssetURLs(release *ReleaseInfo, archiveName string) (archiveURL, checksumURL string, err error)
- func PrintUpdateNotice(out io.Writer, currentVersion string) bool
- func ReplaceBinary(newBinaryPath string) error
- func SaveStateFile(state *UpdateState) error
- func ShouldCheckForUpdate(state *UpdateState) bool
- func ValidateAssetURL(rawURL string) error
- func VerifyChecksum(archivePath, checksumURL string) error
- type Asset
- type CheckResult
- type InstallMethod
- type ReleaseInfo
- type UpdateState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArchiveName ¶
ArchiveName builds the expected archive filename for the current platform.
func CheckAndCache ¶
func CheckAndCache(currentVersion string)
CheckAndCache checks for updates and writes the result to the state file. Intended to run as a goroutine; silently ignores all errors.
func CompareVersions ¶
CompareVersions returns true if latest is newer than current. Both versions may optionally have a "v" prefix.
func DownloadAsset ¶
DownloadAsset downloads a URL to a file in destDir and returns the file path.
func ExtractBinary ¶
ExtractBinary extracts the glab binary from a tar.gz or zip archive.
func FindAssetURLs ¶
func FindAssetURLs(release *ReleaseInfo, archiveName string) (archiveURL, checksumURL string, err error)
FindAssetURLs locates the archive and checksums URLs from a release's assets.
func PrintUpdateNotice ¶
PrintUpdateNotice reads the cached state and prints an update banner if a newer version is available. Returns true if a banner was printed.
func ReplaceBinary ¶
ReplaceBinary replaces the currently running binary with a new one.
func SaveStateFile ¶
func SaveStateFile(state *UpdateState) error
SaveStateFile writes the update state to disk.
func ShouldCheckForUpdate ¶
func ShouldCheckForUpdate(state *UpdateState) bool
ShouldCheckForUpdate returns true if the cache is stale or missing.
func ValidateAssetURL ¶ added in v0.2.0
ValidateAssetURL validates that a URL points to an expected GitHub domain. This prevents downloading from untrusted sources during self-update.
func VerifyChecksum ¶
VerifyChecksum downloads checksums.txt, computes SHA256 of the archive, and verifies the hash matches.
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
}
Asset holds GitHub release asset fields.
type CheckResult ¶
type CheckResult struct {
CurrentVersion string
LatestVersion string
IsNewer bool
ReleaseURL string
Release *ReleaseInfo
}
CheckResult holds the result of a version check.
func CheckLatestRelease ¶
func CheckLatestRelease(currentVersion string) (*CheckResult, error)
CheckLatestRelease queries GitHub for the latest release and compares versions.
type InstallMethod ¶
type InstallMethod int
InstallMethod represents how glab was installed.
const ( InstallBinary InstallMethod = iota // direct binary download InstallBrew // Homebrew InstallDeb // Debian package InstallRPM // RPM package InstallGoBuild // go install / dev build )
func DetectInstallMethod ¶
func DetectInstallMethod() InstallMethod
DetectInstallMethod determines how glab was installed.
type ReleaseInfo ¶
type ReleaseInfo struct {
TagName string `json:"tag_name"`
Assets []Asset `json:"assets"`
HTMLURL string `json:"html_url"`
}
ReleaseInfo holds GitHub release API response fields.
type UpdateState ¶
type UpdateState struct {
LastChecked time.Time `json:"last_checked"`
LatestVersion string `json:"latest_version"`
ReleaseURL string `json:"release_url"`
}
UpdateState is persisted to disk to cache version check results.
func LoadStateFile ¶
func LoadStateFile() (*UpdateState, error)
LoadStateFile reads the cached update state from disk.