update

package
v0.0.0-...-d54492c Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractArchive

func ExtractArchive(src, dest string) (string, error)

ExtractArchive extracts the contents of the archive of the archive at src into the dest directory and returns the extracted file that it believes is the newly upgraded binary. Supports zip and tar.gz formats, which is determined by the file extension.

func IsHomebrew

func IsHomebrew(binary string) bool

IsHomebrew will check if the binary is found under the Homebrew prefix.

Borrowed from https://github.com/cli/cli/blob/6b9a8608f6211f9f46f745b610021492c79c3482/cmd/gh/main.go

func SemVerGreaterThan

func SemVerGreaterThan(release string, current string) (bool, error)

SemVerGreaterThan returns true if release is greater than current

func SemVerLessThan

func SemVerLessThan(release string, current string) (bool, error)

SemVerLessThan returns true if release is less than current

func UpgradeFromLocalFile

func UpgradeFromLocalFile(cliUpgradeData cliUpgrade) error

UpgradeFromLocalFile performs an upgrade given an upgrade configuration.

Types

type CLIDependency

type CLIDependency struct {
	// contains filtered or unexported fields
}

CLIDependency contains information about the current version and the latest CLI release version from Slack CLI metadata

func NewCLIDependency

func NewCLIDependency(clients *shared.ClientFactory, version string) *CLIDependency

NewCLIDependency creates and returns a new instance of CLIDependency

func (*CLIDependency) CheckForUpdate

func (c *CLIDependency) CheckForUpdate(ctx context.Context) error

CheckForUpdate retrieves and sets the LatestCLIRelease that describes the latest update available directly to the CLIDependency instance Synchronous version of CheckForUpdateInBackground

func (*CLIDependency) HasUpdate

func (c *CLIDependency) HasUpdate() (bool, error)

func (*CLIDependency) InstallUpdate

func (c *CLIDependency) InstallUpdate(ctx context.Context) error

InstallUpdate grabs the latest version of the CLI binary and installs it onto the system

func (*CLIDependency) PrintUpdateNotification

func (c *CLIDependency) PrintUpdateNotification(cmd *cobra.Command) (bool, error)

PrintUpdateNotification notifies the user that a new version is available and provides upgrade instructions for Homebrew. Returns a bool representing whether the user wants the self-update to run

type CLIReleaseInfo

type CLIReleaseInfo struct {
	SlackCLI struct {
		Title       string `json:"title"`
		Description string `json:"description"`
		Releases    []struct {
			Version     string `json:"version"`
			ReleaseDate string `json:"release_date"`
		} `json:"releases"`
	} `json:"slack-cli"`
}

CLIReleaseInfo stores information about most recent release's version and release date

type Dependency

type Dependency interface {
	CheckForUpdate(ctx context.Context) error
	PrintUpdateNotification(cmd *cobra.Command) (bool, error)
	HasUpdate() (bool, error)
	InstallUpdate(ctx context.Context) error
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient interface

type LatestCLIRelease

type LatestCLIRelease struct {
	Version string
}

type Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

func (*Metadata) CheckForUpdate

func (md *Metadata) CheckForUpdate(ctx context.Context, url, currentVersion string) (*LatestCLIRelease, error)

checkForUpdate returns the release info from CLI meta including the most recent CLI version that is an upgrade to the currentVersion parameter or nil if no upgrade is available.

type SDKDependency

type SDKDependency struct {
	// contains filtered or unexported fields
}

SDKDependency contains the latest release information for dependencies used by a given project

func NewSDKDependency

func NewSDKDependency(clients *shared.ClientFactory) *SDKDependency

NewSDKDependency creates and returns a new instance of SDKDependency

func (*SDKDependency) CheckForUpdate

func (c *SDKDependency) CheckForUpdate(ctx context.Context) error

CheckForUpdate executes the `check-update` hook, if available, and sets the release information to the SDKDependency instance

func (*SDKDependency) HasUpdate

func (c *SDKDependency) HasUpdate() (bool, error)

HasUpdate returns true if the SDK has an update available

func (*SDKDependency) InstallUpdate

func (c *SDKDependency) InstallUpdate(ctx context.Context) error

InstallUpdate executes the `install-update` hook, if available, and prints information about the execution of available updates

func (*SDKDependency) PrintUpdateNotification

func (c *SDKDependency) PrintUpdateNotification(cmd *cobra.Command) (bool, error)

PrintUpdateNotification prints out the update message returned from the SDK, including formatting and language that indicates if a breaking change is included or an error has occurred

type SDKInstallUpdateComponent

type SDKInstallUpdateComponent struct {
	Name             string `json:"name"`
	PreviousVersion  string `json:"previous"`
	InstalledVersion string `json:"installed"`
	Error            struct {
		Message string `json:"message,omitempty"`
	} `json:"error"`
}

SDKInstallUpdateComponent contains the information about a given SDK dependency's install update

type SDKInstallUpdateResponse

type SDKInstallUpdateResponse struct {
	Name    string                      `json:"name"`
	Updates []SDKInstallUpdateComponent `json:"updates"`
	Error   struct {
		Message string `json:"message,omitempty"`
	} `json:"error"`
}

SDKInstallUpdateResponse contains information following the attempted updating of dependencies used within a given project

type SDKReleaseComponent

type SDKReleaseComponent struct {
	Name     string `json:"name"`
	Current  string `json:"current"`
	Latest   string `json:"latest"`
	Breaking bool   `json:"breaking"`
	Update   bool   `json:"update"`
	Message  string `json:"message"`
	URL      string `json:"url"`
	Error    struct {
		Message string `json:"message"`
	} `json:"error"`
}

SDKReleaseComponent contains the information about a given SDK dependency's update status

type SDKReleaseInfo

type SDKReleaseInfo struct {
	Name     string `json:"name"`
	Breaking bool
	Update   bool
	Releases []SDKReleaseComponent `json:"releases"`
	Message  string                `json:"message"`
	URL      string                `json:"url"`
	Error    struct {
		Message string `json:"message"`
	} `json:"error"`
}

SDKReleaseInfo contains the information about updates available for the dependencies used within a given project

func CheckUpdateHook

func CheckUpdateHook(ctx context.Context, clients *shared.ClientFactory) (SDKReleaseInfo, error)

CheckUpdateHook returns the response from the check update hook

type UpdateNotification

type UpdateNotification struct {
	// contains filtered or unexported fields
}

UpdateNotification checks for an update (non-blocking in the background or blocking). It provides the release information for the latest update of each dependency.

func New

func New(clients *shared.ClientFactory, cliVersion string, envDisabled string) *UpdateNotification

New is the constructor for UpdateNotification that sets good defaults.

func (*UpdateNotification) CheckForUpdate

func (u *UpdateNotification) CheckForUpdate(ctx context.Context, shouldForceUpdateCheck bool) error

CheckForUpdate has each dependency perform a self-check for available updates. This is the synchronous version of CheckForUpdateInBackground

func (*UpdateNotification) CheckForUpdateInBackground

func (u *UpdateNotification) CheckForUpdateInBackground(ctx context.Context, shouldForceUpdateCheck bool)

CheckForUpdateInBackground starts a Go routine that checks for an update every hoursSinceLastUpdateCheck (e.g. 24 hours). The shouldForceUpdateCheck param can be used to force the update check, regardless of the time since the last check.

func (*UpdateNotification) Dependencies

func (u *UpdateNotification) Dependencies() []Dependency

Dependencies returns the dependencies to check for updates.

func (*UpdateNotification) Enabled

func (u *UpdateNotification) Enabled() bool

Enabled returns true if checking for the latest version is enabled.

func (*UpdateNotification) Env

func (u *UpdateNotification) Env() string

Env returns the environment variable to disable update notifications.

func (*UpdateNotification) HasUpdate

func (u *UpdateNotification) HasUpdate() bool

HasUpdate returns true if any dependency has an update available.

func (*UpdateNotification) Hours

func (u *UpdateNotification) Hours() float64

Hours returns the number of hours to wait between checking for updates.

func (*UpdateNotification) PrintAndPromptUpdates

func (u *UpdateNotification) PrintAndPromptUpdates(cmd *cobra.Command, cliVersion string) error

PrintUpdates displays an update message after the command runs and prompts the user if they want to update, if applicable Invoked from root command's post-run method. If an error occurs, we return it so it is raised to the user.

func (*UpdateNotification) SetEnabled

func (u *UpdateNotification) SetEnabled(b bool)

SetEnabled enables or disables checking for the latest version. Default is true.

func (*UpdateNotification) SetEnv

func (u *UpdateNotification) SetEnv(s string)

SetEnv sets an environment variable to disable update notifications.

func (*UpdateNotification) SetHours

func (u *UpdateNotification) SetHours(h float64)

SetHours sets the number of hours to wait between checking for updates.

func (*UpdateNotification) WaitForCheckForUpdateInBackground

func (u *UpdateNotification) WaitForCheckForUpdateInBackground() bool

WaitForCheckForUpdateInBackground must be called after CheckForUpdateInBackground and will block until the go routine finishes. Returns boolean that indicates if updates have been retrieved.

Jump to

Keyboard shortcuts

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