update

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 12 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.

var ExportNewOfflineUpdater NewOfflineUpdaterFunc = func(props *p.Props) Updater {
	return setup.NewOfflineUpdater(props.Tool, props.Logger, props.FS)
}

Deprecated: ExportNewOfflineUpdater is a package-level test seam that races under parallel tests. Inject a factory with WithOfflineUpdater instead. Retained for one minor release for backward compatibility; it is consulted only as the default when no WithOfflineUpdater option is given.

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.

var ExportNewUpdater NewUpdaterFunc = func(ctx context.Context, props *p.Props, version string, force bool) (Updater, error) {
	return setup.NewUpdater(ctx, props, version, force)
}

Deprecated: ExportNewUpdater is a package-level test seam that races under parallel tests. Inject a factory with WithUpdater instead. Retained for one minor release for backward compatibility; it is consulted only as the default when no WithUpdater option is given.

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. The parallel-safe replacement for mutating the deprecated ExportNewOfflineUpdater package var.

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. This is the parallel-safe replacement for mutating the deprecated ExportNewUpdater package var: 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"`
}

UpdateResult contains the outcome of a successful update.

func Update

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

Update downloads and installs the specified version (or latest) of the tool.

type Updater

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

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