From 43136fc51e2e0dc39c4fd939a248457ba0cd75ab Mon Sep 17 00:00:00 2001 From: "fletcher.fan" Date: Wed, 17 Dec 2025 13:29:56 +0800 Subject: [PATCH] feat(node): add version subcommand to morphnode --- node/Makefile | 6 +++++- node/cmd/node/main.go | 1 + node/cmd/node/version.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 node/cmd/node/version.go diff --git a/node/Makefile b/node/Makefile index 1ab1e3091..acd835766 100644 --- a/node/Makefile +++ b/node/Makefile @@ -1,8 +1,12 @@ -GITCOMMIT := $(shell git rev-parse HEAD) +GITCOMMIT := $(shell git rev-parse --short HEAD) GITDATE := $(shell git show -s --format='%ct') +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") +BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT) LDFLAGSSTRING +=-X main.GitDate=$(GITDATE) +LDFLAGSSTRING +=-X main.Version=$(VERSION) +LDFLAGSSTRING +=-X main.BuildTime=$(BUILD_TIME) LDFLAGS := -ldflags "$(LDFLAGSSTRING)" morphnode: diff --git a/node/cmd/node/main.go b/node/cmd/node/main.go index 25a5a0a05..faeed7960 100644 --- a/node/cmd/node/main.go +++ b/node/cmd/node/main.go @@ -41,6 +41,7 @@ func main() { app.Action = L2NodeMain app.Commands = []cli.Command{ keyConverterCmd, + versionCmd, } err := app.Run(os.Args) if err != nil { diff --git a/node/cmd/node/version.go b/node/cmd/node/version.go new file mode 100644 index 000000000..427e98f12 --- /dev/null +++ b/node/cmd/node/version.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "runtime" + + "github.com/urfave/cli" +) + +// Version information, set via -ldflags +var ( + Version = "dev" + GitCommit = "unknown" + BuildTime = "unknown" +) + +var versionCmd = cli.Command{ + Name: "version", + Aliases: []string{"v"}, + Usage: "show version information", + Action: func(ctx *cli.Context) error { + fmt.Printf("morphnode %s\n", Version) + fmt.Printf("Git Commit: %s\n", GitCommit) + fmt.Printf("Build Time: %s\n", BuildTime) + fmt.Printf("Go Version: %s\n", runtime.Version()) + fmt.Printf("OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) + return nil + }, +}