update

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArchiveName

func ArchiveName(version string) string

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

func CompareVersions(current, latest string) bool

CompareVersions returns true if latest is newer than current. Both versions may optionally have a "v" prefix.

func DownloadAsset

func DownloadAsset(url, destDir string) (string, error)

DownloadAsset downloads a URL to a file in destDir and returns the file path.

func ExtractBinary

func ExtractBinary(archivePath, destDir string) (string, error)

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

func PrintUpdateNotice(out io.Writer, currentVersion string) bool

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

func ReplaceBinary(newBinaryPath string) error

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

func ValidateAssetURL(rawURL string) error

ValidateAssetURL validates that a URL points to an expected GitHub domain. This prevents downloading from untrusted sources during self-update.

func VerifyChecksum

func VerifyChecksum(archivePath, checksumURL string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL