Move version printing to version package
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
8f70e298bf
commit
b75455d2bd
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
@ -34,7 +33,7 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if showVersion {
|
if showVersion {
|
||||||
printVersion(os.Stdout)
|
version.PrintVersion()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +58,6 @@ func usage() {
|
|||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
func printVersion(w io.Writer) {
|
|
||||||
fmt.Fprintln(w, os.Args[0], version.Package, version.Version)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fatalf(format string, args ...interface{}) {
|
func fatalf(format string, args ...interface{}) {
|
||||||
fmt.Fprintf(os.Stderr, format+"\n", args...)
|
fmt.Fprintf(os.Stderr, format+"\n", args...)
|
||||||
usage()
|
usage()
|
||||||
|
26
version/print.go
Normal file
26
version/print.go
Normal file
@ -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:
|
||||||
|
//
|
||||||
|
// <cmd> <project> <version>
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user