This is an automated email from the ASF dual-hosted git repository.

jimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 7d32bd30 optimize: add missing VERSION file and version support (#895)
7d32bd30 is described below

commit 7d32bd30869a14bf6572726b8ef5f3ebd871da48
Author: WyRainBow <[email protected]>
AuthorDate: Thu Oct 9 10:26:43 2025 +0800

    optimize: add missing VERSION file and version support (#895)
---
 VERSION      | 17 +++++++++++++++++
 cmd/start.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 makefile     |  2 +-
 3 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/VERSION b/VERSION
new file mode 100644
index 00000000..b50100b7
--- /dev/null
+++ b/VERSION
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+v2.0.0-rc01
diff --git a/cmd/start.go b/cmd/start.go
index fdd68bb9..541dc4ef 100644
--- a/cmd/start.go
+++ b/cmd/start.go
@@ -17,6 +17,67 @@
 
 package main
 
+import (
+       "flag"
+       "fmt"
+       "os"
+)
+
+var (
+       // Version information set by build flags
+       Version     string
+       Branch      string
+       Revision    string
+       showVersion bool
+       showHelp    bool
+)
+
+func init() {
+       flag.BoolVar(&showVersion, "version", false, "show version information")
+       flag.BoolVar(&showVersion, "v", false, "show version information")
+       flag.BoolVar(&showHelp, "help", false, "show help information")
+       flag.BoolVar(&showHelp, "h", false, "show help information")
+}
+
 func main() {
+
+       hasV := false
+       hasVersion := false
+
+       for _, arg := range os.Args[1:] {
+               if arg == "-v" {
+                       hasV = true
+               }
+               if arg == "-version" || arg == "--version" {
+                       hasVersion = true
+               }
+       }
+
+       if hasV && hasVersion {
+               fmt.Fprintf(os.Stderr, "Error: cannot use both -v and --version 
at the same time\n")
+               os.Exit(1)
+       }
+
+       flag.Parse()
+       if showHelp {
+               flag.Usage()
+               return
+       }
+
+       if showVersion {
+               versionPrint := Version
+               if versionPrint == "" {
+                       versionPrint = "unknown"
+               }
+               fmt.Printf("Seata-go version: %s\n", versionPrint)
+               if Branch != "" {
+                       fmt.Printf("Branch: %s\n", Branch)
+               }
+               if Revision != "" {
+                       fmt.Printf("Revision: %s\n", Revision)
+               }
+               return
+       }
+
        // start the server
 }
diff --git a/makefile b/makefile
index ce25e203..3649ac4c 100644
--- a/makefile
+++ b/makefile
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 
-VERSION=$(shell cat "./VERSION" 2> /dev/null)
+VERSION=$(shell tail -n 1 "./VERSION" 2> /dev/null)
 
 GO_FLAGS := -ldflags "-X main.Branch=$(GIT_BRANCH) -X 
main.Revision=$(GIT_REVISION) -X main.Version=$(VERSION) -extldflags 
\"-static\" -s -w" -tags netgo
 GO = go


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to