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 ¶
- func Check(ctx context.Context, cfg Config) error
- func Update(ctx context.Context, cfg Config, channel Channel) error
- type Channel
- type Config
- func (c Config) BinaryName() string
- func (c Config) Check(ctx context.Context) error
- func (c Config) DisplayName() string
- func (c Config) LatestRef(ctx context.Context, client *http.Client) (string, error)
- func (c Config) Update(ctx context.Context, dev, stable bool) error
- func (c Config) VersionLink(v string) string
- type ConflictPolicy
- type Option
- func WithBinary(binary string) Option
- func WithFetchTimeout(d time.Duration) Option
- func WithFormula(formula string) Option
- func WithName(name string) Option
- func WithNoProxy() Option
- func WithOnConflict(policy ConflictPolicy) Option
- func WithRemoveTaps(taps ...string) Option
- func WithResolveVersionFunc(fn ResolveVersionFunc) Option
- func WithTap(tap string) Option
- func WithTapURL(url string) Option
- type ResolveVersionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Channel ¶
type Channel int
Channel selects what [Config.Run] installs.
func ChannelFor ¶
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
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 ¶
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
Check implements updater.Updater.
func (Config) DisplayName ¶
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 ¶
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
Update implements updater.Updater, mapping dev/stable onto ChannelFor.
func (Config) VersionLink ¶
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
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
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
WithFormula overrides the Homebrew formula name, which otherwise defaults to the last element of the module path.
func WithName ¶ added in v0.2.0
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
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
WithTap sets the "owner/name" tap hosting the formula; empty means a core formula.
func WithTapURL ¶ added in v0.2.0
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.