brew

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package brew self-updates a Go CLI binary through Homebrew. A tool describes itself with a Config and calls Update; it refreshes the formula, then upgrades (or taps and installs), with a stable and a dev (--HEAD) channel, and trashes stray non-Homebrew copies so the brew install is authoritative. Check reports whether a newer release exists without installing anything.

It is one update mechanism under clive/updater; others (goinstall, github) sit alongside it and share that package's UX helpers. The clog dependency lives here, keeping the core clive package dependency-light for version-only consumers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context, cfg Config) error

Check reports whether a newer release of cfg is available, without installing.

func Update

func Update(ctx context.Context, cfg Config, channel Channel) error

Update installs the latest cfg via Homebrew on the given channel.

Types

type Channel

type Channel int

Channel selects what [Config.Run] installs.

const (
	// Upgrade upgrades an installed formula to its latest version (the default).
	Upgrade Channel = iota
	// Stable installs the latest stable release, replacing any dev build.
	Stable
	// Dev builds and installs the latest source (HEAD).
	Dev
)

func ChannelFor

func ChannelFor(dev, stable bool) Channel

ChannelFor maps a --dev/--stable flag pair to a Channel; neither set is Upgrade.

type Config

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

Config identifies the tool for a Homebrew self-update. Build it with New: only the module info is required - the formula name defaults to the module's last path element, overridden with WithFormula - and optional behaviour is set with the With* [Option]s. It satisfies updater.Tool for notify.

func New added in v0.2.0

func New(info clive.Info, opts ...Option) Config

New builds a Config for a Homebrew self-update. info carries the module and repo used for version checks and release links; the Homebrew formula name defaults to the last element of the module path and is overridden with WithFormula. Optional behaviour is configured with the With* [Option]s.

func (Config) BinaryName

func (c Config) BinaryName() string

BinaryName is the executable/command name, defaulting to the formula. Shared by other update mechanisms (the periodic check) that name the `<binary> update` command.

func (Config) Check added in v0.2.7

func (c Config) Check(ctx context.Context) error

Check implements updater.Updater.

func (Config) DisplayName

func (c Config) DisplayName() string

DisplayName is the human-facing name used in messages, defaulting to the binary (and thus the formula) name when Name is unset.

func (Config) LatestRef

func (c Config) LatestRef(ctx context.Context, client *http.Client) (string, error)

LatestRef returns the highest semver tag in the tool's repository, delegating to clive.Info.LatestTag. It lets Config satisfy updater.Tool.

func (Config) Update added in v0.2.7

func (c Config) Update(ctx context.Context, dev, stable bool) error

Update implements updater.Updater, mapping dev/stable onto ChannelFor.

func (c Config) VersionLink(v string) string

VersionLink renders v as a clickable link to its release or commit, delegating to the embedded clive.Info. It lets Config satisfy updater.Tool.

type ConflictPolicy

type ConflictPolicy int

ConflictPolicy decides what an update does with copies of the binary found on PATH outside Homebrew, which would otherwise shadow the brew install.

const (
	// ConflictWarn leaves stray non-Homebrew copies in place but warns about each
	// one. It is the zero value, and thus the default.
	ConflictWarn ConflictPolicy = iota
	// ConflictUninstall trashes stray copies (recoverable, falling back to a
	// permanent remove where the platform cannot trash) so the brew install is
	// authoritative.
	ConflictUninstall
	// ConflictIgnore leaves stray copies in place silently.
	ConflictIgnore
)

type Option added in v0.2.0

type Option func(*Config)

Option customises a Config built by New.

func WithBinary added in v0.2.0

func WithBinary(binary string) Option

WithBinary sets the executable name to clean up non-Homebrew copies of and to read the post-update version from; it defaults to the formula name.

func WithFetchTimeout added in v0.2.0

func WithFetchTimeout(d time.Duration) Option

WithFetchTimeout bounds the initial `brew update` formula refresh; the zero value uses a two-minute default. Raise it on a slow link, or lower it to fail faster.

func WithFormula added in v0.2.0

func WithFormula(formula string) Option

WithFormula overrides the Homebrew formula name, which otherwise defaults to the last element of the module path.

func WithName added in v0.2.0

func WithName(name string) Option

WithName sets the human-facing display name shown in messages, e.g. "NGINX" for the nginx formula; it defaults to the binary (and thus formula) name.

func WithNoProxy added in v0.2.0

func WithNoProxy() Option

WithNoProxy clears the proxy variables for the brew subprocesses, so an update bypasses a proxy that cannot reach Homebrew or the formula's source.

func WithOnConflict added in v0.2.0

func WithOnConflict(policy ConflictPolicy) Option

WithOnConflict sets how non-Homebrew copies of the binary on PATH are handled; the default warns that each one may shadow the brew install.

func WithRemoveTaps added in v0.2.0

func WithRemoveTaps(taps ...string) Option

WithRemoveTaps lists Homebrew taps to untap before installing, so a formula that has moved to a new tap is not resolved from a stale one. Best-effort.

func WithResolveVersionFunc added in v0.2.4

func WithResolveVersionFunc(fn ResolveVersionFunc) Option

WithResolveVersionFunc sets how the Homebrew-managed binary's version is read; the zero value runs `<binary> version`.

func WithTap added in v0.2.0

func WithTap(tap string) Option

WithTap sets the "owner/name" tap hosting the formula; empty means a core formula.

func WithTapURL added in v0.2.0

func WithTapURL(url string) Option

WithTapURL sets the git remote for the tap, needed for a private tap brew cannot resolve by name; empty lets brew resolve a public tap.

type ResolveVersionFunc added in v0.2.4

type ResolveVersionFunc func(ctx context.Context, bin string) (string, error)

ResolveVersionFunc returns the version reported by the Homebrew-managed binary at bin.

Jump to

Keyboard shortcuts

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