Documentation
¶
Overview ¶
Package update checks whether a newer jamformer release is available and works out how to tell the user to upgrade.
Three things keep this from getting in the way. The check runs in the background from a short-lived goroutine, so a slow or unreachable network never delays a run; its result is cached on disk so a request goes out at most once a day; and the advice it prints names the upgrade command for the way this binary was actually installed, because "a new version is available" with no next step is a notification, not help.
Index ¶
Constants ¶
const (
// ReleasesPage is where a user without a package manager goes.
ReleasesPage = "https://github.com/" + repo + "/releases/latest"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InstallMethod ¶
type InstallMethod int
InstallMethod is how this binary got onto the machine, which decides the upgrade instruction.
const ( // InstallUnknown covers anything not positively identified. The releases // page is always correct advice, so this is a safe default rather than a // failure. InstallUnknown InstallMethod = iota // InstallHomebrew is a binary under a Homebrew prefix or Cellar. InstallHomebrew // InstallGoInstall is a binary in GOBIN / GOPATH/bin. InstallGoInstall // InstallSource is a binary sitting in a source checkout. InstallSource // InstallPackage is a system path a macOS .pkg or a manual copy installs // to. InstallPackage )
func DetectInstallMethod ¶
func DetectInstallMethod() InstallMethod
DetectInstallMethod works out how this binary was installed, from where it sits on disk. Every branch is a guess about a filesystem layout, so the unknown case has to stay useful: it points at the releases page, which is right however the binary arrived.
func (InstallMethod) String ¶
func (m InstallMethod) String() string
String names the method, for -version output and tests.
type Result ¶
type Result struct {
// Available is true only when a strictly newer release was found.
Available bool
// Current and Latest are the two versions compared, without a leading "v".
Current string
Latest string
// URL is the release's page.
URL string
// Method is how this binary appears to have been installed.
Method InstallMethod
}
Result carries the outcome of a check.
func Check ¶
Check looks for a newer release than current. It returns an error only for the caller's information: every caller treats a failed check as "no notice" rather than a problem, because an update check is not part of the job the user asked for.
The check is skipped, with no error, when the current version is not a release version (a `go build` from source reports "dev", and there is nothing meaningful to compare), or when JAMFORMER_SKIP_UPDATE_CHECK is set.
func (Result) UpgradeHint ¶
UpgradeHint returns the command or action to upgrade, phrased for the detected install method.