diff --git a/Makefile b/Makefile index fd22ce1..d9f4670 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/cmd/control.go b/cmd/control.go index b65579c..2cec607 100644 --- a/cmd/control.go +++ b/cmd/control.go @@ -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) diff --git a/cmd/main.go b/cmd/main.go index 242367b..d459cd5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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{ diff --git a/cmd/version.go b/cmd/version.go index 4597d2d..d4abe03 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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) -} diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..8866f6f --- /dev/null +++ b/version/version.go @@ -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) +}