diff --git a/waku.go b/waku.go index 0825e285..6fedaccb 100644 --- a/waku.go +++ b/waku.go @@ -8,6 +8,7 @@ import ( "github.com/urfave/cli/v2" "github.com/waku-org/go-waku/waku" "github.com/waku-org/go-waku/waku/cliutils" + "github.com/waku-org/go-waku/waku/v2/node" "github.com/waku-org/go-waku/waku/v2/utils" ) @@ -187,12 +188,6 @@ func main() { Usage: "specifies where logging output should be written (stdout, file, file:./filename.log)", Destination: &options.LogOutput, }, - &cli.BoolFlag{ - Name: "version", - Value: false, - Usage: "prints the version", - Destination: &options.Version, - }, &cli.StringFlag{ Name: "agent-string", Value: "go-waku", @@ -455,8 +450,15 @@ func main() { rlnFlags := rlnFlags() cliFlags = append(cliFlags, rlnFlags...) + cli.VersionFlag = &cli.BoolFlag{ + Name: "version", + Usage: "prints the version", + } + app := &cli.App{ - Flags: cliFlags, + Name: "gowaku", + Version: node.GetVersionInfo().String(), + Flags: cliFlags, Action: func(c *cli.Context) error { utils.InitLogger(options.LogEncoding, options.LogOutput) diff --git a/waku/node.go b/waku/node.go index e06b1136..7fa8aad4 100644 --- a/waku/node.go +++ b/waku/node.go @@ -175,11 +175,6 @@ func Execute(options Options) { return } - if options.Version { - fmt.Printf("version / git commit hash: %s-%s\n", node.Version, node.GitCommit) - return - } - if options.UseDB { if options.PersistPeers { // Create persistent peerstore diff --git a/waku/options.go b/waku/options.go index 972ac99d..acfb05c8 100644 --- a/waku/options.go +++ b/waku/options.go @@ -153,7 +153,6 @@ type Options struct { UseDB bool DBPath string AdvertiseAddress string - Version bool // TODO: use vflag from urcli ShowAddresses bool LogLevel string LogEncoding string diff --git a/waku/v2/node/const.go b/waku/v2/node/const.go deleted file mode 100644 index 378473df..00000000 --- a/waku/v2/node/const.go +++ /dev/null @@ -1,7 +0,0 @@ -package node - -// GitCommit is a commit hash. -var GitCommit string - -// Version is the version of go-waku at the time of compilation -var Version string diff --git a/waku/v2/node/version.go b/waku/v2/node/version.go new file mode 100644 index 00000000..78098594 --- /dev/null +++ b/waku/v2/node/version.go @@ -0,0 +1,32 @@ +package node + +import ( + "fmt" + "runtime" +) + +// GitCommit is a commit hash. +var GitCommit string + +// Version is the version of go-waku at the time of compilation +var Version string + +type VersionInfo struct { + Version string + Commit string + System string + Golang string +} + +func GetVersionInfo() VersionInfo { + return VersionInfo{ + Version: Version, + Commit: GitCommit, + System: runtime.GOARCH + "/" + runtime.GOOS, + Golang: runtime.Version(), + } +} + +func (v VersionInfo) String() string { + return fmt.Sprintf("%s-%s", v.Version, v.Commit) +} diff --git a/waku/v2/rest/debug.go b/waku/v2/rest/debug.go index cda55548..a18f6073 100644 --- a/waku/v2/rest/debug.go +++ b/waku/v2/rest/debug.go @@ -1,7 +1,6 @@ package rest import ( - "fmt" "net/http" "github.com/gorilla/mux" @@ -48,6 +47,6 @@ func (d *DebugService) getV1Info(w http.ResponseWriter, r *http.Request) { } func (d *DebugService) getV1Version(w http.ResponseWriter, r *http.Request) { - response := VersionResponse(fmt.Sprintf("%s-%s", node.Version, node.GitCommit)) + response := VersionResponse(node.GetVersionInfo().String()) writeErrOrResponse(w, nil, response) } diff --git a/waku/v2/rpc/debug.go b/waku/v2/rpc/debug.go index 473fc60b..63ba8efc 100644 --- a/waku/v2/rpc/debug.go +++ b/waku/v2/rpc/debug.go @@ -1,7 +1,6 @@ package rpc import ( - "fmt" "net/http" "github.com/waku-org/go-waku/waku/v2/node" @@ -36,6 +35,6 @@ func (d *DebugService) GetV1Info(r *http.Request, args *InfoArgs, reply *InfoRep type VersionResponse string func (d *DebugService) GetV1Version(r *http.Request, args *InfoArgs, reply *VersionResponse) error { - *reply = VersionResponse(fmt.Sprintf("%s-%s", node.Version, node.GitCommit)) + *reply = VersionResponse(node.GetVersionInfo().String()) return nil }