diff --git a/cmd/registry/main.go b/cmd/registry/main.go index c19a122fa..c3c5d728b 100644 --- a/cmd/registry/main.go +++ b/cmd/registry/main.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "io" "net/http" _ "net/http/pprof" "os" @@ -34,7 +33,7 @@ func main() { flag.Parse() if showVersion { - printVersion(os.Stdout) + version.PrintVersion() return } @@ -59,10 +58,6 @@ func usage() { flag.PrintDefaults() } -func printVersion(w io.Writer) { - fmt.Fprintln(w, os.Args[0], version.Package, version.Version) -} - func fatalf(format string, args ...interface{}) { fmt.Fprintf(os.Stderr, format+"\n", args...) usage() diff --git a/version/print.go b/version/print.go new file mode 100644 index 000000000..a82bce39f --- /dev/null +++ b/version/print.go @@ -0,0 +1,26 @@ +package version + +import ( + "fmt" + "io" + "os" +) + +// FprintVersion outputs the version string to the writer, in the following +// format, followed by a newline: +// +// +// +// For example, a binary "registry" built from github.com/docker/distribution +// with version "v2.0" would print the following: +// +// registry github.com/docker/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) +}