move version info to separate package

This commit is contained in:
Christian Schwarz 2018-08-26 21:57:19 +02:00
parent ee5445777d
commit 428339e1ad
5 changed files with 35 additions and 28 deletions

View File

@ -20,7 +20,7 @@ ifndef ZREPL_VERSION
$(error cannot infer variable ZREPL_VERSION using git and variable is not overriden by make invocation)
endif
endif
GO_LDFLAGS := "-X github.com/zrepl/zrepl/cmd.zreplVersion=$(ZREPL_VERSION)"
GO_LDFLAGS := "-X github.com/zrepl/zrepl/version.zreplVersion=$(ZREPL_VERSION)"
GO_BUILD := go build -ldflags $(GO_LDFLAGS)

View File

@ -142,7 +142,7 @@ func doControLVersionCmd(cmd *cobra.Command, args []string) {
die()
}
var info ZreplVersionInformation
var info version.ZreplVersionInformation
err = json.NewDecoder(resp.Body).Decode(&info)
if err != nil {
log.Printf("error unmarshaling response: %s", err)

View File

@ -20,10 +20,6 @@ import (
// Printf(format string, v ...interface{})
//}
var (
zreplVersion string // set by build infrastructure
)
type Logger = logger.Logger
var RootCmd = &cobra.Command{

View File

@ -3,7 +3,7 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra"
"runtime"
"github.com/zrepl/zrepl/version"
)
var versionCmd = &cobra.Command{
@ -17,26 +17,6 @@ func init() {
}
func doVersion(cmd *cobra.Command, args []string) {
fmt.Println(NewZreplVersionInformation().String())
fmt.Println(version.NewZreplVersionInformation().String())
}
type ZreplVersionInformation struct {
Version string
RuntimeGOOS string
RuntimeGOARCH string
RUNTIMECompiler string
}
func NewZreplVersionInformation() *ZreplVersionInformation {
return &ZreplVersionInformation{
Version: zreplVersion,
RuntimeGOOS: runtime.GOOS,
RuntimeGOARCH: runtime.GOARCH,
RUNTIMECompiler: runtime.Compiler,
}
}
func (i *ZreplVersionInformation) String() string {
return fmt.Sprintf("zrepl version=%s GOOS=%s GOARCH=%s Compiler=%s",
i.Version, i.RuntimeGOOS, i.RuntimeGOARCH, i.RUNTIMECompiler)
}

31
version/version.go Normal file
View File

@ -0,0 +1,31 @@
package version
import (
"runtime"
"fmt"
)
var (
zreplVersion string // set by build infrastructure
)
type ZreplVersionInformation struct {
Version string
RuntimeGOOS string
RuntimeGOARCH string
RUNTIMECompiler string
}
func NewZreplVersionInformation() *ZreplVersionInformation {
return &ZreplVersionInformation{
Version: zreplVersion,
RuntimeGOOS: runtime.GOOS,
RuntimeGOARCH: runtime.GOARCH,
RUNTIMECompiler: runtime.Compiler,
}
}
func (i *ZreplVersionInformation) String() string {
return fmt.Sprintf("zrepl version=%s GOOS=%s GOARCH=%s Compiler=%s",
i.Version, i.RuntimeGOOS, i.RuntimeGOARCH, i.RUNTIMECompiler)
}