update

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package update finds new audd releases, tells people about them at most once a day, and replaces the binary for installs that no package manager owns.

Index

Constants

View Source
const (
	BrewCommand   = "brew upgrade audd"
	NPMCommand    = "npm install -g @audd/cli@latest"
	NPXCommand    = "npx @audd/cli@latest"
	PipCommand    = "pip install --upgrade audd-cli"
	PipxCommand   = "pipx upgrade audd-cli"
	UVCommand     = "uv tool upgrade audd-cli"
	UVXCommand    = "uvx audd-cli@latest"
	ScoopCommand  = "scoop update audd"
	WingetCommand = "winget upgrade --id AudD.CLI"
	GoCommand     = "go install github.com/AudDMusic/audd-cli/cmd/audd@latest"
	DockerCommand = "docker pull ghcr.io/auddmusic/audd-cli:latest"
)

Commands for installs a package manager owns.

View Source
const CheckInterval = 24 * time.Hour

CheckInterval is how often the release check runs.

View Source
const ChecksumsName = "checksums.txt"

ChecksumsName is the release file with the SHA-256 of every archive.

View Source
const DefaultAPIBase = "https://api.github.com"

DefaultAPIBase is the GitHub API.

View Source
const Repo = "AudDMusic/audd-cli"

Repo is the GitHub repository releases come from.

Variables

View Source
var ErrNoAsset = errors.New("the release has no build for this system")

ErrNoAsset means the release has no build for this system.

Functions

func APIBase

func APIBase() string

APIBase returns the GitHub API base, or AUDD_UPDATE_URL when set (tests).

func Apply

func Apply(ctx context.Context, client *http.Client, rel *Release, exe, goos, goarch string) error

Apply downloads the release's archive for goos/goarch, checks it against checksums.txt, and replaces the binary at exe with the one inside.

func ArchiveName

func ArchiveName(version, goos, goarch string) string

ArchiveName is the release archive for a system: audd_<version>_<os>_<arch>.tar.gz, or .zip on Windows.

func BinaryName

func BinaryName(goos string) string

BinaryName is the executable inside the archive.

func Newer

func Newer(latest, current string) bool

Newer reports whether latest is a newer version than current. Versions that do not parse are never newer.

func Notice

func Notice(current string, s State, m Method) string

Notice is the line shown when a newer release is cached, or "".

func NoticeAllowed

func NoticeAllowed(env NoticeEnv) bool

NoticeAllowed reports whether to check for and announce updates: only with stderr on a terminal, never in CI, and not with AUDD_NO_UPDATE_CHECK set.

func RemoveOld

func RemoveOld(exe string)

RemoveOld deletes the previous binary that an update on Windows leaves at exe+".old" (a running .exe can be renamed but not deleted). Errors are ignored: the file may not exist, or may still be in use.

func SaveState

func SaveState(dir string, s State) error

SaveState writes the cached check to dir.

Types

type Asset

type Asset struct {
	Name string
	URL  string
}

Asset is a downloadable file of a release.

type Method

type Method struct {
	Name string `json:"method"` // homebrew, npm, npx, pip, pipx, uv, uvx, scoop, winget, go, docker, binary
	// Command updates this install; empty for SelfUpdate installs.
	Command string `json:"command,omitempty"`
	// SelfUpdate is true when audd replaces its own binary.
	SelfUpdate bool `json:"self_update"`
}

Method is how audd was installed, which decides how it is updated.

func DetectMethod

func DetectMethod(exe, goos string, getenv func(string) string) Method

DetectMethod works out how the binary at exe was installed. A package can say so with AUDD_INSTALL_METHOD (the Docker image sets "docker"); otherwise the path decides. getenv reads AUDD_INSTALL_METHOD, GOPATH, and GOBIN.

type NoticeEnv

type NoticeEnv struct {
	StderrTTY bool
	Getenv    func(string) string
}

NoticeEnv is what decides whether the update notice may be shown.

type Release

type Release struct {
	Version string  `json:"version"` // without the leading "v"
	Tag     string  `json:"tag"`
	URL     string  `json:"url"` // the release page
	Assets  []Asset `json:"-"`
}

Release is a published audd release.

func Latest

func Latest(ctx context.Context, client *http.Client, base string) (*Release, error)

Latest asks GitHub for the newest release.

func (*Release) Asset

func (r *Release) Asset(name string) (Asset, bool)

Asset returns the asset with this name.

type State

type State struct {
	CheckedAt time.Time `json:"checked_at"`
	Latest    string    `json:"latest"`
	URL       string    `json:"url,omitempty"`
	// NoticedAt is when the update notice was last shown.
	NoticedAt time.Time `json:"noticed_at,omitzero"`
}

State is the cached result of the last release check.

func LoadState

func LoadState(dir string) State

LoadState reads the cached check from dir; a missing or broken file gives an empty State.

func (State) Due

func (s State) Due(now time.Time) bool

Due reports whether the cached check is older than CheckInterval.

func (State) NoticeDue

func (s State) NoticeDue(now time.Time) bool

NoticeDue reports whether the update notice may be shown again: it appears at most once per CheckInterval.

Jump to

Keyboard shortcuts

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