Skip to content

Commit 8013799

Browse files
committed
refactor: refactor version handling into dedicated package
- Move Version and Commit variables to a new version package - Update LDFLAGS to set version information in the new package - Refactor version command to use version package variables Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 849a434 commit 8013799

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ GO ?= go
22
EXECUTABLE := codegpt
33
GOFILES := $(shell find . -type f -name "*.go")
44
TAGS ?=
5-
LDFLAGS ?= -X 'github.com/appleboy/CodeGPT/cmd.Version=$(VERSION)' -X 'github.com/appleboy/CodeGPT/cmd.Commit=$(COMMIT)'
5+
LDFLAGS ?= -X 'github.com/appleboy/CodeGPT/version.Version=$(VERSION)' -X 'github.com/appleboy/CodeGPT/version.Commit=$(COMMIT)'
66

77
ifneq ($(shell uname), Darwin)
88
EXTLDFLAGS = -extldflags "-static" $(null)
@@ -55,4 +55,4 @@ build_windows_64:
5555
.PHONY: help
5656
help:
5757
@echo 'Usage:'
58-
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
58+
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

cmd/version.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@ package cmd
33
import (
44
"fmt"
55

6+
"github.com/appleboy/CodeGPT/version"
67
"github.com/spf13/cobra"
78
)
89

9-
var (
10-
Version string = ""
11-
Commit string = ""
12-
)
13-
1410
var versionCmd = &cobra.Command{
1511
Use: "version",
1612
Short: "Print the application version and commit information",
1713
Run: func(cmd *cobra.Command, args []string) {
18-
fmt.Println("version:", Version, "commit:", Commit)
14+
fmt.Println("version:", version.Version, "commit:", version.Commit)
1915
},
2016
}

version/version.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package version
2+
3+
var (
4+
Version string = ""
5+
Commit string = ""
6+
)

0 commit comments

Comments
 (0)