selfupdate

package
v1.0.89 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 11 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
	PnpmAvailable 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
	InstallPnpm
	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 {
	// Brand selects the skills index/source endpoints (zero value = feishu).
	Brand core.LarkBrand

	DetectOverride             func() DetectResult
	NpmInstallOverride         func(version string) *NpmResult
	PnpmInstallOverride        func(version string) *NpmResult
	SkillsIndexFetchOverride   func() *NpmResult
	SkillsCommandOverride      func(args ...string) *NpmResult
	SkillsCommandInDirOverride func(dir string, args ...string) *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 / SkillsCommandOverride / 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 the owning package manager is available for auto-update.

func (*Updater) FetchSkillsIndex added in v1.0.88

func (u *Updater) FetchSkillsIndex(source string) *NpmResult

func (*Updater) InstallAllSkills added in v1.0.41

func (u *Updater) InstallAllSkills(source string) *NpmResult

func (*Updater) InstallLocalSuite added in v1.0.88

func (u *Updater) InstallLocalSuite(path string) *NpmResult

func (*Updater) InstallSkills added in v1.0.88

func (u *Updater) InstallSkills(source string, nameList []string) *NpmResult

func (*Updater) ListGlobalSkills added in v1.0.35

func (u *Updater) ListGlobalSkills() *NpmResult

func (*Updater) ListGlobalSkillsJSON added in v1.0.48

func (u *Updater) ListGlobalSkillsJSON() *NpmResult

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) RemoveGlobalSkills added in v1.0.88

func (u *Updater) RemoveGlobalSkills(names []string) *NpmResult

func (*Updater) RunNpmInstall

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

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

func (*Updater) RunPnpmInstall added in v1.0.66

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

RunPnpmInstall executes pnpm add -g @larksuite/cli@<version>.

func (*Updater) SkillsSources added in v1.0.88

func (u *Updater) SkillsSources() []string

SkillsSources returns the brand-specific v0.2 source first, followed by the other brand's source. Falling back must not change the configured brand.

func (*Updater) StageSuite added in v1.0.88

func (u *Updater) StageSuite(source, dir string) *NpmResult

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