update

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package update implements version checking and self-update functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareVersions

func CompareVersions(a, b string) int

CompareVersions compares two semver strings. Strips leading "v" prefix and compares MAJOR.MINOR.PATCH numerically. Returns -1 if a < b, 0 if a == b, 1 if a > b. Malformed versions are treated as 0.0.0.

func PrintBannerIfAvailable

func PrintBannerIfAvailable(stateFile string)

PrintBannerIfAvailable reads the state file and prints a one-line update notice to stderr if an update is available. Errors are silently ignored — the banner is best-effort.

func SaveState

func SaveState(path string, state State) error

SaveState writes the update state to disk atomically. Uses temp file + rename to prevent partial reads by concurrent CLI processes.

func StateFilePath

func StateFilePath(configDir string) string

StateFilePath returns the path to the update state file.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker queries GitHub Releases and updates the state file.

func NewChecker

func NewChecker(currentVersion, stateFile string, logger *slog.Logger) *Checker

NewChecker creates an update checker for the given version and state file path.

func (*Checker) Check

func (c *Checker) Check(method InstallMethod) (State, error)

Check queries GitHub for the latest release, compares versions, and writes the result to the state file. Returns the updated state and any error encountered.

func (*Checker) FetchRelease

func (c *Checker) FetchRelease() (ReleaseInfo, error)

FetchRelease fetches the latest release info from GitHub.

type ErrElevationRequired

type ErrElevationRequired struct {
	Command string
}

ErrElevationRequired indicates the update needs elevated privileges.

func (*ErrElevationRequired) Error

func (e *ErrElevationRequired) Error() string

type InstallMethod

type InstallMethod string

InstallMethod represents how pmux was installed.

const (
	MethodDev      InstallMethod = "dev"
	MethodSnap     InstallMethod = "snap"
	MethodDeb      InstallMethod = "deb"
	MethodRPM      InstallMethod = "rpm"
	MethodHomebrew InstallMethod = "homebrew"
	MethodGitHub   InstallMethod = "github"
)

func Detect

func Detect(buildMethod string) InstallMethod

Detect determines how pmux was installed using runtime heuristics. buildMethod is the value of main.installMethod set via ldflags ("dev" for local builds, empty for release builds).

func (InstallMethod) HasUpdatePath

func (m InstallMethod) HasUpdatePath() bool

HasUpdatePath reports whether this install method has a known update path (either automated or guided with printed instructions).

func (InstallMethod) String

func (m InstallMethod) String() string

String returns a human-readable label for the install method.

type ReleaseAsset

type ReleaseAsset struct {
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url"`
}

ReleaseAsset represents a downloadable file attached to a release.

type ReleaseInfo

type ReleaseInfo struct {
	TagName string         `json:"tag_name"`
	HTMLURL string         `json:"html_url"`
	Assets  []ReleaseAsset `json:"assets"`
}

ReleaseInfo holds data from the GitHub Releases API response.

type State

type State struct {
	LastCheck       time.Time `json:"lastCheck"`
	CurrentVersion  string    `json:"currentVersion"`
	LatestVersion   string    `json:"latestVersion"`
	UpdateAvailable bool      `json:"updateAvailable"`
	ReleaseURL      string    `json:"releaseURL"`
	InstallMethod   string    `json:"installMethod"`
	BinaryPath      string    `json:"binaryPath"` // for cache invalidation
}

State holds the persisted update check result.

func LoadState

func LoadState(path string) (State, error)

LoadState reads the update state from disk. Returns a zero State and nil error if the file does not exist.

type Updater

type Updater interface {
	// Update applies the update for the given release.
	// For methods requiring elevated privileges, it downloads the package
	// and prints the command the user should run.
	Update(release ReleaseInfo) error

	// Description returns a human-readable description of the update method.
	Description() string
}

Updater applies an update using an install-method-specific strategy.

func NewUpdater

func NewUpdater(method InstallMethod, currentVersion string, logger *slog.Logger) Updater

NewUpdater returns the appropriate Updater for the given install method.

Jump to

Keyboard shortcuts

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