distribution/version/get.go
Cory Snider a74cacff04 version: export getter functions
Future-proof the version package's exported interface by only making the
data available through getter functions. This affords us the flexibility
to e.g. implement them in terms of "runtime/debug".ReadBuildInfo() in
the future.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2023-12-19 13:02:44 -05:00

43 lines
1,010 B
Go

package version
import (
"fmt"
"io"
"os"
)
// Package returns the overall, canonical project import path under
// which the package was built.
func Package() string {
return mainpkg
}
// Version returns returns the module version the running binary was
// built from.
func Version() string {
return version
}
// Revision returns the VCS (e.g. git) revision being used to build
// the program at linking time.
func Revision() string {
return revision
}
// FprintVersion outputs the version string to the writer, in the following
// format, followed by a newline:
//
// <cmd> <project> <version>
//
// For example, a binary "registry" built from github.com/distribution/distribution
// with version "v2.0" would print the following:
//
// registry github.com/distribution/distribution v2.0
func FprintVersion(w io.Writer) {
fmt.Fprintln(w, os.Args[0], Package(), Version())
}
// PrintVersion outputs the version information, from Fprint, to stdout.
func PrintVersion() {
FprintVersion(os.Stdout)
}