update

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

go-update

Go Reference CI License

Shared Go library for CLI self-update functionality. Detects the installation method and upgrades using the appropriate strategy — no configuration required from users.

Features

  • Auto-detects Homebrew, dpkg, rpm, or standalone binary installation
  • Homebrew: runs brew update first so the tap is current, then upgrades and verifies
  • dpkg / rpm: downloads the package from GitHub Releases and installs with sudo
  • Binary: downloads the archive, verifies SHA-256 checksum, replaces the binary in-place
  • Safe: never reports success unless the installed version actually changed

Installation

go get github.com/bluefunda/go-update

Usage

package cmd

import (
    "github.com/bluefunda/go-update"
    "github.com/spf13/cobra"
)

var updateCmd = &cobra.Command{
    Use:   "update",
    Short: "Update mycli to the latest version",
    Long: `Check for a newer release and upgrade automatically.
The installation method (Homebrew, dpkg, rpm, standalone binary) is
detected from the current executable path.`,
    RunE: func(cmd *cobra.Command, args []string) error {
        return update.Run(update.Config{
            BinaryName:     "mycli",
            CurrentVersion: Version, // injected at build time via ldflags
            GitHubOwner:    "myorg",
            GitHubRepo:     "myrepo",
            HomebrewCask:   "mycli", // formula name in your homebrew tap
        })
    },
}
User experience
$ mycli update
Checking for updates...

Current: mycli v1.2.0
Latest:  v1.3.0

Update available.

Continue? [y/N] y

Updating via Homebrew...

==> Upgrading mycli
...
✓ Successfully updated to v1.3.0

How detection works

Condition Method
Executable path contains homebrew, linuxbrew, or /cellar/ Homebrew
dpkg -S <exe> succeeds (Linux) dpkg
rpm -qf <exe> succeeds (Linux) rpm
None of the above Binary (direct GitHub Releases download)

GitHub Releases format

For the binary upgrader, releases must follow GoReleaser naming conventions:

<binary>_<version>_<os>_<arch>.tar.gz   # Linux
<binary>_<version>_<os>_<arch>.zip      # macOS / Windows
checksums.txt                            # SHA-256 checksums

dpkg and rpm packages:

<binary>_<version>_linux_<arch>.deb
<binary>_<version>_linux_<arch>.rpm

Contributing

See CONTRIBUTING.md.

License

Apache 2.0 — see LICENSE.

Documentation

Overview

Package update provides CLI self-update functionality for BlueFunda CLIs. It detects the installation method (Homebrew, dpkg, rpm, or standalone binary) and performs the upgrade using the appropriate strategy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(cfg Config) error

Run executes the full self-update flow: check → diff → prompt → upgrade.

Types

type BinaryUpgrader

type BinaryUpgrader struct{}

BinaryUpgrader downloads the archive from GitHub Releases, verifies SHA256, extracts the binary and replaces the current executable in place.

func (*BinaryUpgrader) Name

func (b *BinaryUpgrader) Name() string

func (*BinaryUpgrader) Upgrade

func (b *BinaryUpgrader) Upgrade(cfg Config, version string) error

type BrewUpgrader

type BrewUpgrader struct {
	Cask string
}

BrewUpgrader upgrades via `brew upgrade --cask <cask>`.

func (*BrewUpgrader) Name

func (b *BrewUpgrader) Name() string

func (*BrewUpgrader) Upgrade

func (b *BrewUpgrader) Upgrade(cfg Config, version string) error

type Config

type Config struct {
	// BinaryName is the CLI binary name, e.g. "bai", "abaper", "breq".
	BinaryName string
	// CurrentVersion is the version string injected at build time via ldflags.
	// May be "dev", "v1.2.3", or "1.2.3".
	CurrentVersion string
	// GitHubOwner is the GitHub organisation, e.g. "bluefunda".
	GitHubOwner string
	// GitHubRepo is the GitHub repository name, e.g. "bluefunda-ai".
	GitHubRepo string
	// HomebrewTap is the tap name, e.g. "bluefunda/tap". When set, the tap
	// is trusted before upgrade so Homebrew 4.x loads the formula without
	// requiring the user to run `brew trust` manually.
	HomebrewTap string
	// HomebrewCask is the formula or cask name in the tap, e.g. "bai".
	HomebrewCask string
}

Config holds per-CLI settings for the update command.

type DpkgUpgrader

type DpkgUpgrader struct{}

DpkgUpgrader downloads the .deb from GitHub Releases and installs it with dpkg.

func (*DpkgUpgrader) Name

func (d *DpkgUpgrader) Name() string

func (*DpkgUpgrader) Upgrade

func (d *DpkgUpgrader) Upgrade(cfg Config, version string) error

type Method

type Method int

Method identifies how the CLI was installed.

const (
	MethodBrew   Method = iota // Homebrew formula or cask
	MethodDpkg                 // dpkg / apt-get (Debian/Ubuntu)
	MethodRpm                  // rpm (RHEL/Fedora)
	MethodBinary               // standalone binary (fallback)
)

type RpmUpgrader

type RpmUpgrader struct{}

RpmUpgrader downloads the .rpm from GitHub Releases and installs it with rpm.

func (*RpmUpgrader) Name

func (r *RpmUpgrader) Name() string

func (*RpmUpgrader) Upgrade

func (r *RpmUpgrader) Upgrade(cfg Config, version string) error

type Upgrader

type Upgrader interface {
	// Name returns the human-readable name of the upgrade strategy.
	Name() string
	// Upgrade downloads and installs the given version.
	// version is the plain semver string without "v" prefix (e.g. "1.5.0").
	Upgrade(cfg Config, version string) error
}

Upgrader performs the actual CLI upgrade.

Jump to

Keyboard shortcuts

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