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
- func Truncate(s string, maxLen int) string
- type DetectResult
- type InstallMethod
- type NpmResult
- type Updater
- func (u *Updater) CanRestorePreviousVersion() bool
- func (u *Updater) CleanupStaleFiles()
- func (u *Updater) DetectInstallMethod() DetectResult
- func (u *Updater) PrepareSelfReplace() (restore func(), err error)
- func (u *Updater) RunNpmInstall(version string) *NpmResult
- func (u *Updater) RunSkillsUpdate() *NpmResult
- func (u *Updater) VerifyBinary(expectedVersion string) error
Constants ¶
const (
NpmPackage = "@larksuite/cli"
)
Variables ¶
This section is empty.
Functions ¶
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 ¶
NpmResult holds the result of an npm install or skills update execution.
func (*NpmResult) CombinedOutput ¶
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 (*Updater) CanRestorePreviousVersion ¶
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 ¶
PrepareSelfReplace is a no-op on Unix. Unix allows overwriting a running executable via inode semantics.
func (*Updater) RunNpmInstall ¶
RunNpmInstall executes npm install -g @larksuite/cli@<version>.
func (*Updater) RunSkillsUpdate ¶
RunSkillsUpdate executes npx -y skills add larksuite/cli -g -y.
func (*Updater) VerifyBinary ¶
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).