update

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package update provides version checking and self-update functionality for s9s.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanUpdate

func CanUpdate() error

CanUpdate checks whether the running binary can be updated. go-selfupdate writes to a temp file then renames over the binary, so we check that the parent directory is writable (not the binary itself, which would fail with ETXTBSY on Linux).

func IsNewer

func IsNewer(current, latest string) bool

IsNewer returns true if latest is a newer semver than current. Returns false for dev builds or invalid versions.

Types

type Asset

type Asset struct {
	Name        string
	DownloadURL string
	Size        int64
}

Asset represents a downloadable release artifact.

type Checker

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

Checker queries GitHub for new releases.

func NewChecker

func NewChecker() *Checker

NewChecker creates a Checker for the default s9s repository.

func NewCheckerFor

func NewCheckerFor(owner, repo string) *Checker

NewCheckerFor creates a Checker for a specific GitHub repository.

func (*Checker) LatestRelease

func (c *Checker) LatestRelease(ctx context.Context, includePreRelease bool) (*ReleaseInfo, error)

LatestRelease fetches the latest release from GitHub. If includePreRelease is true, pre-release versions are considered.

type ReleaseInfo

type ReleaseInfo struct {
	Version     string
	TagName     string
	PublishedAt time.Time
	PreRelease  bool
	HTMLURL     string
	Assets      []Asset
}

ReleaseInfo holds information about a GitHub release.

type State

type State struct {
	LastChecked    time.Time `json:"lastChecked"`
	LatestVersion  string    `json:"latestVersion"`
	LatestURL      string    `json:"latestURL"`
	CurrentVersion string    `json:"currentVersion"`
}

State persists update check metadata.

func LoadState

func LoadState() *State

LoadState reads the update state from ~/.s9s/update-state.json. Returns an empty state (not an error) if the file is missing or corrupt.

func LoadStateFrom

func LoadStateFrom(dir string) *State

LoadStateFrom reads the update state from a specific directory.

func (*State) NeedsCheck

func (s *State) NeedsCheck(interval time.Duration) bool

NeedsCheck returns true if enough time has passed since the last check.

func (*State) Save

func (s *State) Save() error

Save writes the state to ~/.s9s/update-state.json atomically.

func (*State) SaveTo

func (s *State) SaveTo(dir string) error

SaveTo writes the state to a specific directory atomically.

type UpdateOptions

type UpdateOptions struct {
	PreRelease    bool
	Force         bool   // skip "already up to date" check
	TargetVersion string // update to a specific version (e.g. "v0.7.0"); empty = latest
}

UpdateOptions configures the self-update behavior.

type UpdateResult

type UpdateResult struct {
	PreviousVersion string
	NewVersion      string
	ReleaseURL      string
}

UpdateResult contains the outcome of an update operation.

type Updater

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

Updater performs the self-update of the s9s binary.

func NewUpdater

func NewUpdater() *Updater

NewUpdater creates an Updater with the current build version.

func (*Updater) Update

func (u *Updater) Update(ctx context.Context, opts UpdateOptions) (*UpdateResult, error)

Update downloads and installs the latest release, replacing the running binary.

Jump to

Keyboard shortcuts

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