Documentation
¶
Overview ¶
Package update provides small, dependency-free helpers for deciding whether a self-update should proceed.
It is designed to be useful for any CLI that updates itself from signed releases (for example, from GitHub releases), where you want conservative guardrails and clear user messaging.
This package intentionally does not perform downloads, signature verification, checksum verification, or installation. It focuses on deciding whether an update should proceed given a current version and a target release tag.
Version model
- Supports semver-like strings in the form "vMAJOR.MINOR[.PATCH]" with optional prerelease/build metadata (e.g., "v0.2.5-rc1", "v1.0.0+build123").
- Prerelease precedence follows SemVer: "0.2.5-rc1" < "0.2.5".
- "dev", "0.0.0-dev", and empty versions are treated as non-comparable and default to proceeding (developer escape hatch).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareSemver ¶
CompareSemver compares two normalized semver-like strings. Returns -1 if a < b, 0 if a == b, 1 if a > b. Supports MAJOR.MINOR[.PATCH] with optional prerelease/build metadata; build metadata is ignored. Returns an error if either version cannot be parsed.
func DescribeDecision ¶
DescribeDecision returns a human-readable dry-run status.
func FormatVersionDisplay ¶
FormatVersionDisplay formats a version string for display, adding "v" prefix if needed.
func NormalizeVersion ¶
NormalizeVersion strips the leading "v" prefix and validates that the version is semver-like (at least MAJOR.MINOR, optionally with PATCH, prerelease, and/or build metadata). Returns the normalized version string and a boolean indicating whether comparison is possible. "dev", empty strings, and non-semver formats return ("", false).
Types ¶
type Decision ¶
type Decision string
const ( DecisionProceed Decision = "proceed" // Proceed with update DecisionSkip Decision = "skip" // Skip, already at target version DecisionRefuse Decision = "refuse" // Refuse (e.g., cross-major without force) DecisionReinstall Decision = "reinstall" // Force reinstall same version DecisionDowngrade Decision = "downgrade" // Explicit downgrade with --tag DecisionDevInstall Decision = "devinstall" // Installing release from dev build )
func DecideSelfUpdate ¶
DecideSelfUpdate determines whether a self-update should proceed.
current: running binary version (e.g. "0.2.5" or "dev") target: target release tag (e.g. "v0.2.6") explicitTag: true if user specified --tag (allows downgrades) force: true if --self-update-force was specified
Returns a Decision, a human message, and an exit code suggestion (0=success/skip, 1=refuse).