selfupdate

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package selfupdate handles installation detection, npm-based updates, skills updates, and platform-specific binary replacement for the CLI self-update flow.

Index

Constants

View Source
const (
	NpmPackage = "@larksuite/cli"
)

Variables

This section is empty.

Functions

func Truncate

func Truncate(s string, maxLen int) string

Truncate returns the last maxLen runes of s.

Types

type DetectResult

type DetectResult struct {
	Method       InstallMethod
	ResolvedPath string
	NpmAvailable bool
}

DetectResult holds installation detection results.

func (DetectResult) CanAutoUpdate

func (d DetectResult) CanAutoUpdate() bool

CanAutoUpdate returns true if the CLI can update itself automatically.

func (DetectResult) ManualReason

func (d DetectResult) ManualReason() string

ManualReason returns a human-readable explanation of why auto-update is unavailable.

type InstallMethod

type InstallMethod int

InstallMethod describes how the CLI was installed.

const (
	InstallNpm InstallMethod = iota
	InstallManual
)

type NpmResult

type NpmResult struct {
	Stdout bytes.Buffer
	Stderr bytes.Buffer
	Err    error
}

NpmResult holds the result of an npm install or skills update execution.

func (*NpmResult) CombinedOutput

func (r *NpmResult) CombinedOutput() string

CombinedOutput returns stdout + stderr concatenated.

type Updater

type Updater struct {
	DetectOverride           func() DetectResult
	NpmInstallOverride       func(version string) *NpmResult
	SkillsUpdateOverride     func() *NpmResult
	VerifyOverride           func(expectedVersion string) error
	RestoreAvailableOverride func() bool
	// contains filtered or unexported fields
}

Updater manages self-update operations. Platform-specific methods (PrepareSelfReplace, CleanupStaleFiles) are in updater_unix.go and updater_windows.go.

Override DetectOverride / NpmInstallOverride / SkillsUpdateOverride / VerifyOverride / RestoreAvailableOverride for testing.

func New

func New() *Updater

New creates an Updater with default (real) behavior.

func (*Updater) CanRestorePreviousVersion

func (u *Updater) CanRestorePreviousVersion() bool

CanRestorePreviousVersion reports whether PrepareSelfReplace created a restorable backup for the current update attempt.

func (*Updater) CleanupStaleFiles

func (u *Updater) CleanupStaleFiles()

CleanupStaleFiles is a no-op on Unix (no .old files are created).

func (*Updater) DetectInstallMethod

func (u *Updater) DetectInstallMethod() DetectResult

DetectInstallMethod determines how the CLI was installed and whether npm is available for auto-update.

func (*Updater) PrepareSelfReplace

func (u *Updater) PrepareSelfReplace() (restore func(), err error)

PrepareSelfReplace is a no-op on Unix. Unix allows overwriting a running executable via inode semantics.

func (*Updater) RunNpmInstall

func (u *Updater) RunNpmInstall(version string) *NpmResult

RunNpmInstall executes npm install -g @larksuite/cli@<version>.

func (*Updater) RunSkillsUpdate

func (u *Updater) RunSkillsUpdate() *NpmResult

RunSkillsUpdate executes npx -y skills add larksuite/cli -g -y.

func (*Updater) VerifyBinary

func (u *Updater) VerifyBinary(expectedVersion string) error

VerifyBinary checks that the installed binary reports the expected version by running "lark-cli --version" and comparing the version token exactly. Output format is "lark-cli version X.Y.Z"; the last field is extracted and compared against expectedVersion (both stripped of any "v" prefix).

Jump to

Keyboard shortcuts

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