update

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package update implements `spec update`: it brings the locally installed spec binary to the newest released version by delegating to whatever mechanism manages the install (Homebrew, go install, or a raw release binary it self-replaces). The engine is split into a side-effect-free Plan phase and a mutating Apply phase so `--check` never touches the system.

Index

Constants

View Source
const DevVersion = "dev"

DevVersion is the sentinel version stamped into binaries built without a release tag (the default value of cmd.Version). It never compares as up-to-date, so `spec update` always offers an upgrade for dev builds.

Variables

This section is empty.

Functions

func CheckLatest added in v0.24.0

func CheckLatest(ctx context.Context, current string) (latest string, available bool)

CheckLatest reports the newest released version when it is newer than current, for the passive "update available" notice in the TUI. It reuses the same release source, semver comparison, and token resolution as `spec update`, differing only in one deliberate policy: it never nags development builds.

It runs a live query on every call (the TUI invokes it once per startup, off the UI thread, bounded by the release source's 10s HTTP timeout). There is no on-disk cache: a release surfaces on the very next launch for every user, rather than being masked for up to a day by a stale cached "latest". The query is best-effort and degrades silently — any error (network down, rate-limited) yields ("", false), never a surfaced error, because an ambient notice must never disrupt the session.

func GitHubToken added in v0.24.0

func GitHubToken() string

GitHubToken returns an optional GitHub token to lift the anonymous API rate limit. Public release lookups work without it; it is read best-effort from the standard environment variables. This is the single source of truth for token resolution shared by `spec update` and the passive TUI check.

func IsDev

func IsDev(v string) bool

IsDev reports whether v is an untagged development build.

Types

type Asset

type Asset struct {
	Name string
	URL  string
}

Asset is a single downloadable file attached to a release.

type Method

type Method string

Method identifies how the running binary was installed, which determines the mechanism `spec update` delegates to.

const (
	// MethodHomebrew indicates a Homebrew-managed install (brew upgrade).
	MethodHomebrew Method = "homebrew"
	// MethodGoInstall indicates a `go install`-managed install.
	MethodGoInstall Method = "go-install"
	// MethodBinary indicates a raw release binary with no package manager;
	// `spec update` self-replaces it from the GitHub release.
	MethodBinary Method = "binary"
)

func DetectMethod

func DetectMethod(execPath string) Method

DetectMethod classifies how the executable at execPath was installed. The path is resolved through symlinks first so a Homebrew shim in bin/ is traced back to its Cellar location.

type Options

type Options struct {
	// CurrentVersion is the version stamped into the running binary.
	CurrentVersion string
	// ExecPath is the path to the running executable (os.Executable()).
	ExecPath string
	// TargetVersion pins a specific release tag; empty means latest.
	TargetVersion string
	// Force proceeds even when already on the target version.
	Force bool
}

Options configures an update run.

type Plan

type Plan struct {
	Method          Method `json:"method"`
	CurrentVersion  string `json:"current_version"`
	LatestVersion   string `json:"latest_version"`
	UpdateAvailable bool   `json:"update_available"`
	// contains filtered or unexported fields
}

Plan describes the intended update without performing it. It is produced by Plan and consumed by Apply, and is also the payload for `--check`/`--json`.

type Release

type Release struct {
	Tag    string
	Assets []Asset
}

Release is the subset of a GitHub release that `spec update` needs.

type Updater

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

Updater orchestrates an update run against a release source.

func NewUpdater

func NewUpdater(token string) *Updater

NewUpdater builds an Updater backed by the live GitHub release API.

func (*Updater) Apply

func (u *Updater) Apply(ctx context.Context, plan *Plan, stdout, stderr io.Writer) error

Apply performs the update described by plan, streaming any subprocess output to stdout/stderr. It is a no-op (nil error) when no update is available and Force was not set. The caller is responsible for any confirmation prompt.

func (*Updater) Plan

func (u *Updater) Plan(ctx context.Context, opts Options) (*Plan, error)

Plan resolves the target release and managing mechanism and compares it against the running version. It performs no mutations.

Jump to

Keyboard shortcuts

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