From b75455d2bd09b48cf55952562eeb82d6a516199c Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 29 Jan 2015 15:53:26 -0800 Subject: [PATCH] Move version printing to version package Signed-off-by: Stephen J Day --- cmd/registry/main.go | 7 +------ version/print.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 version/print.go 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) +}