Documentation
¶
Overview ¶
Package update implements lstk's self-update: checking GitHub for a newer release and applying it through whichever mechanism installed lstk (Homebrew, npm, or replacing the binary in place).
On the binary channel an update installs the whole set a release archive carries (lstk, the bundled-extensions binary, lstk-extensions.toml) with a stage-then-commit scheme (extract.go). The guarantees to preserve:
- A file under its real name is never truncated or half-written: content is only ever written to a fresh staging file and renamed into place.
- An interrupted update is repaired by re-running `lstk update`: nothing commits until everything is staged, leftovers are cleaned first, and lstk commits last, so a working lstk always remains. Windows caveat: a crash between renaming lstk.exe aside and renaming the new one in leaves no lstk.exe; rename lstk.exe.old back by hand.
- Nothing is deleted: only the members the archive carries are written, so an archive without the bundle (a rollback) replaces lstk alone.
An archive carrying only lstk installs exactly as before bundling existed.
The pre-bundling updater installs a bundling release with only its lstk binary. A release build that then finds neither bundle member beside itself (DetectMissingBundle) points the user at a reinstall, from the unknown-command error and from an up-to-date `lstk update`.
Index ¶
- Constants
- func Check(ctx context.Context, sink output.Sink, githubToken string) (string, bool, error)
- func CheckQuietly(ctx context.Context, githubToken string) (current, latest string, available bool)
- func NotifyUpdate(ctx context.Context, sink output.Sink, opts NotifyOptions) (exitAfter bool)
- func Update(ctx context.Context, sink output.Sink, checkOnly bool, githubToken string, ...) error
- type InstallInfo
- type InstallMethod
- type MissingBundle
- type NotifyOptions
Constants ¶
const ReinstallLabel = "Restore extensions:"
ReinstallLabel introduces Reinstall wherever it is rendered: as an error action's label, and inside the update warning's sentence. It names the goal rather than the action, so it does not restate the instruction it labels.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check reports whether a newer version is available. Returns the latest version string and true if an update is available. Always emits exactly one UpdateCheckedEvent, whose DevBuild/Available fields tell the sink which of the three possible outcomes (dev build skipped / already up to date / an update is available) occurred.
func CheckQuietly ¶ added in v0.5.2
func NotifyUpdate ¶ added in v0.5.2
func Update ¶
func Update(ctx context.Context, sink output.Sink, checkOnly bool, githubToken string, force bool) error
Update checks for updates and applies one if available.
When it would apply, it first refuses installs it must not replace (see blockSelfUpdate) — ahead of the version check and download, so an install lstk cannot write to fails immediately rather than after fetching and verifying an archive it can never install. --check is exempt: it writes nothing, and its answer is useful however lstk was installed.
Types ¶
type InstallInfo ¶
type InstallInfo struct {
Method InstallMethod
Manager string
ResolvedPath string
}
InstallInfo holds the detected install method and the resolved binary path.
func DetectInstallMethod ¶
func DetectInstallMethod() InstallInfo
DetectInstallMethod determines how lstk was installed by inspecting the resolved path of the running binary.
type InstallMethod ¶
type InstallMethod int
const ( InstallBinary InstallMethod = iota // standalone binary download InstallHomebrew // installed via Homebrew cask InstallNPM // installed via npm InstallExternal // managed by an external tool (nix, mise, ...) )
func (InstallMethod) String ¶
func (m InstallMethod) String() string
String names the install method itself. Distinct from appliedMethodName, which names how an update was *performed* for the --json envelope: a forced update of an external install replaces the binary, so it reports "binary" while the method here is still "external".
type MissingBundle ¶ added in v1.1.0
type MissingBundle struct {
Dir string // install directory that should hold the bundle
Reinstall string // what restores the complete set
}
MissingBundle describes an install of a bundling release whose bundled extensions are not beside lstk: what the pre-bundling updater leaves behind when it installs a bundling release. Homebrew and npm replace the whole package, so they never end up here.
func DetectMissingBundle ¶ added in v1.1.0
func DetectMissingBundle() (MissingBundle, bool)
DetectMissingBundle reports whether the running lstk is a release build (version.BundlesExtensions), installed as a plain binary, with no bundle beside it. Dev builds never report one.
func DetectMissingBundleFor ¶ added in v1.1.0
func DetectMissingBundleFor(command string) (MissingBundle, bool)
DetectMissingBundleFor is DetectMissingBundle limited to the commands the bundle provided at the time of the transition, so a typo never earns a reinstall hint. Retire it with the hint once every supported release ships the set-wise updater.
func (MissingBundle) Summary ¶ added in v1.1.0
func (m MissingBundle) Summary() string
Summary is the one-sentence explanation shown wherever the state is reported.
type NotifyOptions ¶ added in v0.5.2
type NotifyOptions struct {
GitHubToken string
// CanPrompt reports whether this call site can block at all (an interactive
// TTY). Independent of Mode, the user's preference: a non-interactive start
// only ever emits a note, however Mode is set.
CanPrompt bool
// CheckEnabled is the resolved `[cli] check_for_update_on_startup`.
CheckEnabled bool
PersistUpdateCheck func(enabled bool) error
// DetectInstall resolves how lstk itself was installed. Injected so tests
// do not depend on where the test binary lives, which is also what makes
// the prompt path's apply-time guard testable. Defaults to
// DetectInstallMethod when nil.
DetectInstall func() InstallInfo
}