Documentation
¶
Overview ¶
Package clive provides version detection, display, and "latest version" lookup for Go CLIs.
Callers inject build metadata via -ldflags:
-X github.com/gechr/clive.version=$(VERSION) -X github.com/gechr/clive.buildTime=$(BUILDTIME)
When ldflags are not set (e.g. `go install ...@latest` or `go build` without flags), Current falls back to debug.BuildInfo so the binary still reports a sensible version string.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Current ¶
func Current() string
Current returns the version string for the running binary, computing it once and caching the result.
Resolution order:
- ldflag-injected `version` (Makefile path)
- debug.BuildInfo Main.Version (Go module proxy / `go install`)
- debug.BuildInfo vcs.revision (plain `go build`)
Dev versions are normalised so a trailing "-dev" is preserved or appended as appropriate.
func DeriveVersion ¶
DeriveVersion resolves a display version from Go build metadata. A module version (set by `go install module@version` via the module proxy) is preferred over a VCS revision (from a plain `go build`). It returns "" when neither is available. Current uses it as the fallback when no version was injected via ldflags.
Types ¶
type Info ¶
type Info struct {
// Module is the Go module path, e.g. "github.com/gechr/clone".
// Required by Latest.
Module string
// Repo is the GitHub "owner/name" used to build release/commit URLs.
// If empty and Module starts with "github.com/", Repo is derived from it.
Repo string
}
Info identifies the binary for version-link and latest-lookup purposes. The zero value is usable for Current/Print but Latest and VersionLink require Module (and Repo for hyperlinks).
func (Info) Latest ¶
Latest queries the Go module proxy for the latest published version of i.Module. Returns the raw `result.Version` string from `go list -m -json`. Requires `go` on PATH.
func (Info) PrintDetailed ¶
func (i Info) PrintDetailed()
PrintDetailed writes a labelled table of version, Go runtime, OS/arch, build time, and VCS info. When i.Repo (or i.Module) is set, the version row is rendered as a clickable terminal hyperlink.
func (Info) UpdateAvailable ¶ added in v0.0.2
UpdateAvailable reports whether a newer version of i.Module is available on the module proxy than the currently running binary. It returns (false, nil) when the current version cannot be parsed or is already the latest. Requires `go` on PATH.
func (Info) VersionLink ¶
VersionLink returns v rendered as a clickable terminal hyperlink to the matching GitHub tag (release versions) or commit (dev versions). If i has no usable Repo, v is returned unchanged.
Directories
¶
| Path | Synopsis |
|---|---|
|
update
|
|
|
brew
Package brew self-updates a Go CLI binary through Homebrew.
|
Package brew self-updates a Go CLI binary through Homebrew. |
|
Package version provides version parsing helpers shared by clive and its subpackages.
|
Package version provides version parsing helpers shared by clive and its subpackages. |