cliupdate

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cliupdate lets the CLI find a newer release and replace its own executable with it, reusing selfupgrade's download, checksum and signature code.

Index

Constants

View Source
const (
	ChannelStable = "stable"
	ChannelBeta   = "beta"
)

Channel names accepted by Source.Channel.

View Source
const (
	ActionUpToDate   = "up-to-date"
	ActionWouldApply = "would-update"
	ActionUpdated    = "updated"
)

Actions reported in Result.Action.

Variables

View Source
var ErrManagedPath = errors.New("the running executable is managed by a package manager")

ErrManagedPath means a package manager owns the executable.

View Source
var ErrNotWritable = errors.New("cannot write next to the running executable")

ErrNotWritable means the executable's directory cannot take a staged file.

Functions

func Asset

func Asset(base, goos, goarch string) string

Asset names the CLI release asset the way release.yml does.

func ExecutablePath

func ExecutablePath() (string, error)

ExecutablePath returns the running binary with symlinks resolved, so the swap replaces the real file and never a link.

func ManagedPathHint

func ManagedPathHint(path string) string

ManagedPathHint returns the right update command when path sits under a package manager's tree, or "" when the CLI is self-managed.

func Newer

func Newer(current, latest string) bool

Newer reports whether latest is a higher release than current. A dev build or an unparsable version never reports newer.

Types

type Hinter

type Hinter struct {
	Source  Source
	Current string
	// Dir is the CLI's config directory, where the check result is cached.
	Dir string
	// IntervalDays of 0 or less disables the hint.
	IntervalDays int
	Now          func() time.Time
}

Hinter prints a one-line notice at most once per Interval days.

func (Hinter) Check

func (h Hinter) Check(ctx context.Context) string

Check returns the line to print, or "" when there is nothing to say. It never returns an error: every failure just means no hint this time.

type Options

type Options struct {
	Source Source
	// Current is the running version, Target an explicit tag ("" means latest).
	Current string
	Target  string
	DryRun  bool
	// Force skips the package-manager path refusal.
	Force bool
	// ExePath is the resolved path of the running executable.
	ExePath string
	// TUFCacheDir keeps Sigstore trust metadata between runs.
	TUFCacheDir string
	// Confirm runs after the plan is known and before any download; an error aborts.
	Confirm func(current, target string) error
	// Verify checks the signature over checksums.txt. Nil verifies in process,
	// in require mode, so a release without a valid signature is never applied.
	Verify func(ctx context.Context, checksumsPath, bundlePath string) (string, error)
}

Options configures one update run.

type Result

type Result struct {
	Action       string `json:"action"`
	Current      string `json:"current"`
	Target       string `json:"target"`
	Asset        string `json:"asset"`
	Path         string `json:"path"`
	Verification string `json:"verification,omitempty"`
	Backup       string `json:"backup,omitempty"`
}

Result describes what a run did or would do.

func Update

func Update(ctx context.Context, o Options) (Result, error)

Update replaces o.ExePath with the target release after verifying it. On any error before the final rename the current binary is untouched.

type Source

type Source struct {
	// Repo is "owner/name".
	Repo string
	// APIBase serves the releases listing, for example https://api.github.com.
	APIBase string
	// DownloadBase is the asset prefix, the tag is appended by the fetcher.
	DownloadBase string
	// Asset is the release asset for this OS and arch.
	Asset string
	// Channel is "stable" (stable only), "beta" (prereleases count too) or ""
	// (stable, else the newest prerelease), the same rules as install-cli.sh.
	Channel string
	Client  *http.Client
	// AllowHTTP permits plain http bases, for tests against a local server.
	AllowHTTP bool
}

Source says where releases are published and which asset belongs to this build.

func (Source) Latest

func (s Source) Latest(ctx context.Context) (string, error)

Latest returns the highest tag on s.Channel that ships s.Asset; the default channel falls back to a prerelease when there is no stable one. An empty tag with a nil error means nothing suitable is published.

Jump to

Keyboard shortcuts

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