Documentation
¶
Overview ¶
Package update checks GitHub Releases for a newer `teams` and reports it.
It is the one thing in the CLI that talks to a host other than the configured cloud, so it is deliberately small, opt-out and boring:
- it is never automatic in a non-interactive run (PLAN.md:351) and never runs at all when `TEAMS_NO_UPDATE_CHECK` is set or `update_check = false` is in the config;
- an answer is cached for DefaultInterval in the profile's state dir, so a daily check is one request a day at most;
- every failure is the caller's to swallow: an offline machine, a rate limit or a proxy must never turn into a CLI error.
The release list it reads is public and carries no user data; the request sends no token and no identifying header beyond the User-Agent the CLI sets everywhere.
Index ¶
Constants ¶
const ( // DefaultAPIBase is GitHub's REST API root. The check never follows a // redirect off this host, and the base is only overridden by the in-process // tests (there is no flag or environment variable for it, so a released // binary cannot be pointed elsewhere). DefaultAPIBase = "https://api.github.com" // DefaultRepoPath is the GitHub Releases endpoint for this project. DefaultRepoPath = "/repos/floriscornel/teams-cli/releases/latest" // DefaultInterval is how long a cached answer is reused. DefaultInterval = 24 * time.Hour // DefaultTimeout bounds the check's own request. It is short on purpose: a // user who did not ask for the check must never wait for it. DefaultTimeout = 3 * time.Second )
Defaults for Options.
Variables ¶
var ErrInvalidVersion = errors.New("update: not a version")
ErrInvalidVersion reports a version string that is not semver-like.
Functions ¶
func Compare ¶
Compare orders two version strings: -1 when a is older, 0 when they are the same version, +1 when a is newer.
It implements the semver ordering rules that matter here (semver 2.0.0 §11): an optional "v" prefix, dot-separated numeric parts, an optional prerelease that sorts *below* the same version without one, and build metadata (+…) that is ignored. A missing part counts as zero, so "1.0" and "1.0.0" are equal. A plain `go build` reports "dev", which callers detect separately rather than asking Compare to order it.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker performs the check. It is safe to reuse.
func (*Checker) Check ¶
Check answers from the cache when the cached answer is still fresh, and otherwise asks GitHub.
func (*Checker) Unversioned ¶
Unversioned reports whether the running binary has a version worth comparing.
type Options ¶
type Options struct {
// Current is the running binary's version, as the CLI reports it ("0.4.0",
// "v0.4.0", "v0.4.0-rc.1" or "dev").
Current string
// APIBase overrides the GitHub API root. Tests only.
APIBase string
// RepoPath overrides the releases endpoint. Tests only.
RepoPath string
// HTTPClient defaults to a client with the check's own timeout.
HTTPClient *http.Client
// CachePath is where the last answer is stored. Empty disables caching, so
// every check is a request.
CachePath string
// Interval is how long a cached answer is trusted.
Interval time.Duration
// Now is the injected clock; it decides whether a cached answer is stale.
Now func() time.Time
// UserAgent is sent with the request.
UserAgent string
}
Options configures a Checker. Current is required; everything else has a default.
type Result ¶
type Result struct {
// Current is the version being compared, as the binary reports it.
Current string
// Latest is the newest published release's tag, when one was found.
Latest string
// URL is the release's page on GitHub.
URL string
// PublishedAt is when that release was published, when GitHub said.
PublishedAt time.Time
// Outdated reports that Latest is newer than Current.
Outdated bool
// CheckedAt is when the answer was fetched, or when a cached one was
// originally fetched.
CheckedAt time.Time
// FromCache reports that no request was made.
FromCache bool
// Unversioned reports a build that has no version to compare (a plain
// `go build`); Latest is still reported, but Outdated stays false.
Unversioned bool
}
Result is what a check found.