Skip to content

Commit

Permalink
cmd: add version (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Jan 9, 2023
1 parent 483af7d commit 6be0611
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
# limitations under the License.

GOBIN := $(shell pwd)/bin
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD)
COMMIT ?= $(shell git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty)
DEBUG ?=
DOCKERPREFIX ?=
BUILD_TAGS ?=
LDFLAGS ?=
BUILDFLAGS := $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags '${BUILD_TAGS}'
BUILDFLAGS := $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS) -X main.Version=$(VERSION) -X main.Commit=$(COMMIT)' -tags '$(BUILD_TAGS)'
ifneq ("$(DEBUG)", "")
BUILDFLAGS += -race
endif
Expand Down
11 changes: 9 additions & 2 deletions cmd/tiproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package main

import (
"fmt"
"os"

"github.com/pingcap/TiProxy/lib/config"
Expand All @@ -26,10 +27,16 @@ import (
"github.com/spf13/cobra"
)

var (
Version = "test"
Commit = "test commit"
)

func main() {
rootCmd := &cobra.Command{
Use: os.Args[0],
Short: "start the proxy server",
Use: os.Args[0],
Short: "start the proxy server",
Version: fmt.Sprintf("%s, commit %s", Version, Commit),
}

configFile := rootCmd.PersistentFlags().String("config", "", "proxy config file path")
Expand Down
7 changes: 7 additions & 0 deletions cmd/tiproxyctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
package main

import (
"fmt"
"os"
"strings"

"github.com/pingcap/TiProxy/lib/cli"
"github.com/pingcap/TiProxy/lib/util/cmd"
)

var (
Version = "test"
Commit = "test commit"
)

func main() {
rootCmd := cli.GetRootCmd(nil)
rootCmd.Version = fmt.Sprintf("%s, commit %s", Version, Commit)
rootCmd.Use = strings.Replace(rootCmd.Use, "tiproxyctl", os.Args[0], 1)
cmd.RunRootCommand(rootCmd)
}

0 comments on commit 6be0611

Please sign in to comment.