updater

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package updater holds the shared surface for clive's self-update mechanisms. Each mechanism is a sibling subpackage - brew (Homebrew), goinstall (`go install`), and github (release assets) - that describes a tool with its own Config and exposes Check/Update. This package owns the pieces those Configs have in common: the Tool interface that consumers such as notify depend on, and the cross-mechanism UX helpers (Report, UpToDate, Spin), install directory resolution (InstallDir), and subprocess-environment helpers (ProxyBypass, GoPrivate).

It deliberately does not define a behavioural Updater interface over Check/Update: each mechanism's Channel enum differs, and nothing drives an updater polymorphically. The clog dependency lives here and in the subpackages, keeping the core clive package dependency-light.

Index

Constants

This section is empty.

Variables

View Source
var DefaultHintColor color.Color = lipgloss.Color("208")

DefaultHintColor is the orange accent for the update hint.

Functions

func DisplayName

func DisplayName(name, binary string) string

DisplayName resolves the human-facing name shown in messages: name when set, else the binary name. Shared by every mechanism's Config.DisplayName.

func GoPrivate

func GoPrivate(module, existing string) string

GoPrivate returns a GOPRIVATE value that includes module, preserving any existing entries so the caller's configuration is not discarded. Both inputs are trimmed so surrounding whitespace never yields a malformed list.

func Hint

func Hint(displayName, binaryName, installed, latest string, accent color.Color)

Hint logs the shared "you're behind" update hint: the 💡 symbol, the installed and latest refs as fields, and a "<name> is outdated! Run `<binary> update` to upgrade" message with the command emphasised in accent. It is the single renderer used by every mechanism's Check and by notify, so the active and passive update paths read identically. installed and latest are already display-formatted.

func HintFor

func HintFor(tool Tool, current, latest string)

HintFor logs the default-styled update hint for a tool, formatting current and latest through the tool's VersionLink. It is the convenience each Check uses.

func InstallDir

func InstallDir(dir string) string

InstallDir resolves the directory a binary is installed into: dir when set (with a leading "~/" and any env vars expanded), else ~/.local/bin. It returns "" only when no dir was given and the home directory cannot be resolved, letting a caller fall back to a mechanism-specific default.

func ProxyBypass

func ProxyBypass() []string

ProxyBypass returns env entries that disable any inherited proxy for an update subprocess: each proxy variable is blanked (an empty value overrides the inherited one) and NO_PROXY is set to "*" so every host is exempt. Both the upper- and lower-case spellings are set, as tools read either.

func Report

func Report(name string, info clive.Info, old, current string)

Report logs the result of an update as an old→new pair when the version changed, and otherwise defers to UpToDate. Both old and current may carry a leading "v"; it is stripped before comparison and display.

func Spin

func Spin(ctx context.Context, msg string, fn func(context.Context) error, fields ...Field) error

Spin runs fn under a clog spinner labelled msg, with any fields attached: on success it logs a completion line, and on failure it returns fn's error without the spinner logging its own error line, so the caller reports the failure exactly once.

func UpToDate

func UpToDate(name string, info clive.Info, ver string)

UpToDate warns that no update was applied, including the version field only when a version is known (a go-run build has none to show).

Types

type Field

type Field struct {
	Key string
	Val string
}

Field is an optional structured key/value attached to a Spin message, shown on both the spinner and its completion line (e.g. version="1.2.3").

type Tool

type Tool interface {
	// BinaryName is the executable/command name, e.g. "myapp".
	BinaryName() string
	// DisplayName is the human-facing name shown in messages.
	DisplayName() string
	// VersionLink renders v as a clickable link to its release/commit.
	VersionLink(v string) string
	// LatestRef returns the newest installable ref of the tool, fetched over the
	// network without a toolchain so a distributed binary can call it. Each
	// mechanism answers in its own currency: brew and goinstall report the
	// highest semver tag in the repository, while github - which installs release
	// assets - reports the latest release's tag, so a consumer's "update
	// available" signal matches what the updater can actually fetch. A nil client
	// uses [http.DefaultClient].
	LatestRef(ctx context.Context, client *http.Client) (string, error)
}

Tool is the metadata a consumer needs to describe a self-updating CLI without depending on how it updates. The brew, goinstall, and github Configs each satisfy it. VersionLink and LatestRef are methods rather than an Info() accessor because Config carries Info as a field, and a struct cannot expose both a field Info and a method Info.

Directories

Path Synopsis
Package brew self-updates a Go CLI binary through Homebrew.
Package brew self-updates a Go CLI binary through Homebrew.
Package github self-updates a Go CLI binary from its GitHub releases.
Package github self-updates a Go CLI binary from its GitHub releases.
Package goinstall self-updates a Go CLI binary through `go install`.
Package goinstall self-updates a Go CLI binary through `go install`.

Jump to

Keyboard shortcuts

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