Help us shape the future of Go! Take the 2026 Go Developer Survey

update

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 14 Imported by: 0

README

Update Command

Updates the tool to the latest or specified version.

For detailed information on update processes and migration, see the Built-in Commands Documentation.

Documentation

Overview

Package update provides the Cobra command for self-updating the CLI binary to the latest released version from the configured release source (GitHub or GitLab), with support for private repositories via token authentication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCmdUpdate

func NewCmdUpdate(props *p.Props, opts ...UpdateConfigOption) *setup.Command

NewCmdUpdate creates the update command for self-updating the tool binary. The optional [UpdateConfigOption]s are threaded into both the online and offline update paths — pass WithUpdater / WithOfflineUpdater to inject test doubles without mutating any package-level seam (parallel-safe).

func UpdateConfig

func UpdateConfig(ctx context.Context, props *p.Props, binPath string, opts ...UpdateConfigOption)

UpdateConfig re-runs the init flow after a successful update to ensure config compatibility.

Types

type NewOfflineUpdaterFunc added in v0.17.0

type NewOfflineUpdaterFunc func(props *p.Props) Updater

NewOfflineUpdaterFunc constructs an Updater for offline, file-based updates.

type NewUpdaterFunc added in v0.17.0

type NewUpdaterFunc func(ctx context.Context, props *p.Props, version string, force bool) (Updater, error)

NewUpdaterFunc constructs an Updater for online updates.

type UpdateConfigOption

type UpdateConfigOption func(*updateConfigOptions)

UpdateConfigOption configures the UpdateConfig function.

func WithExecCommand

func WithExecCommand(fn func(context.Context, string, ...string) *exec.Cmd) UpdateConfigOption

WithExecCommand overrides exec.CommandContext for testing.

func WithOfflineUpdater added in v0.17.0

func WithOfflineUpdater(fn NewOfflineUpdaterFunc) UpdateConfigOption

WithOfflineUpdater injects the offline Updater factory, replacing the default that builds a real setup.NewOfflineUpdater.

func WithUpdater added in v0.17.0

func WithUpdater(fn NewUpdaterFunc) UpdateConfigOption

WithUpdater injects the online Updater factory, replacing the default that builds a real setup.NewUpdater. Each call site receives its own factory, so concurrent tests cannot clobber one another.

type UpdateResult

type UpdateResult struct {
	PreviousVersion string `json:"previous_version"`
	NewVersion      string `json:"new_version"`
	Updated         bool   `json:"updated"`
	RolledBack      bool   `json:"rolled_back"`
	Pinned          string `json:"pinned,omitempty"`
}

UpdateResult contains the outcome of a successful update.

func Pin added in v0.49.0

func Pin(ctx context.Context, props *p.Props, target string, force bool, out io.Writer, opts ...UpdateConfigOption) (*UpdateResult, error)

Pin keeps the tool on the running version when target is empty, with no network call; otherwise it installs target and keeps the tool there (spec 0104 D4).

func Rollback added in v0.49.0

func Rollback(ctx context.Context, props *p.Props, target string, force bool, out io.Writer, opts ...UpdateConfigOption) (*UpdateResult, error)

Rollback installs target, or the release before the running one when target is empty, after confirmation, and pins it (spec 0104 D2, D3, D5). force skips the confirmation, which an unattended run cannot give otherwise.

func Unpin added in v0.49.0

func Unpin(props *p.Props) (*UpdateResult, error)

Unpin clears the pin so updates resume.

func Update

func Update(ctx context.Context, props *p.Props, version string, force bool, out io.Writer, opts ...UpdateConfigOption) (*UpdateResult, error)

Update downloads and installs the specified version (or latest) of the tool. A pinned tool stays put unless a version is named or force is set, and then the pin moves to what was installed (spec 0104 D7).

type Updater

type Updater interface {
	GetLatestVersionString(ctx context.Context) (string, error)
	Update(ctx context.Context) (string, error)
	UpdateFromFile(ctx context.Context, filePath string) (string, error)
	GetReleaseNotes(ctx context.Context, from, to string) (string, error)
	GetCurrentVersion() string
	ReleaseBefore(ctx context.Context, current string) (string, error)
}

Updater defines the interface for self-updating functionality.

Jump to

Keyboard shortcuts

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