refactor: gowaku version

This commit is contained in:
Richard Ramos 2022-11-25 21:55:54 -04:00 committed by RichΛrd
parent 7e74155dca
commit 5243124af5
7 changed files with 43 additions and 24 deletions

16
waku.go
View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

32
waku/v2/node/version.go Normal file
View File

@ -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)
}

View File

@ -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)
}

View File

@ -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
}