2015-01-29 15:53:26 -08:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2023-12-19 13:02:44 -05:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2015-01-29 15:53:26 -08:00
|
|
|
// FprintVersion outputs the version string to the writer, in the following
|
|
|
|
// format, followed by a newline:
|
|
|
|
//
|
2022-11-02 22:05:45 +01:00
|
|
|
// <cmd> <project> <version>
|
2015-01-29 15:53:26 -08:00
|
|
|
//
|
2020-08-24 13:18:39 +02:00
|
|
|
// For example, a binary "registry" built from github.com/distribution/distribution
|
2015-01-29 15:53:26 -08:00
|
|
|
// with version "v2.0" would print the following:
|
|
|
|
//
|
2022-11-02 22:05:45 +01:00
|
|
|
// registry github.com/distribution/distribution v2.0
|
2015-01-29 15:53:26 -08:00
|
|
|
func FprintVersion(w io.Writer) {
|
2023-12-19 13:02:44 -05:00
|
|
|
fmt.Fprintln(w, os.Args[0], Package(), Version())
|
2015-01-29 15:53:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// PrintVersion outputs the version information, from Fprint, to stdout.
|
|
|
|
func PrintVersion() {
|
|
|
|
FprintVersion(os.Stdout)
|
|
|
|
}
|