From 46a4d03b760f1c8c771b8de980919aa88e2c24b1 Mon Sep 17 00:00:00 2001 From: nite07 Date: Tue, 19 Mar 2024 23:35:13 +0800 Subject: [PATCH] fix: version cmd --- .goreleaser.pre.yaml | 2 +- .goreleaser.yaml | 2 +- Dockerfile | 2 +- cmd/root.go | 4 ---- cmd/version.go | 3 ++- constant/version.go | 3 +++ main.go | 7 ------- 7 files changed, 8 insertions(+), 15 deletions(-) create mode 100644 constant/version.go diff --git a/.goreleaser.pre.yaml b/.goreleaser.pre.yaml index 976e761..2ace5bf 100644 --- a/.goreleaser.pre.yaml +++ b/.goreleaser.pre.yaml @@ -12,7 +12,7 @@ builds: - arm - "386" ldflags: - - -s -w -X sub2sing-box/main.Version={{ .Version }} + - -s -w -X sub2sing-box/constant.Version={{ .Version }} flags: - -trimpath no_unique_dist_dir: true diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e18e55d..7610cfa 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,7 +12,7 @@ builds: - arm - "386" ldflags: - - -s -w -X sub2sing-box/main.Version={{ .Version }} + - -s -w -X sub2sing-box/constant.Version={{ .Version }} flags: - -trimpath no_unique_dist_dir: true diff --git a/Dockerfile b/Dockerfile index 628043e..b03858d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN go mod download ARG version -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X sub2clash/config.Version=${version}" -o sub2sing-box main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X sub2sing-box/constant.Version=${version}" -o sub2sing-box main.go WORKDIR /app diff --git a/cmd/root.go b/cmd/root.go index 6d8c1e7..ebef5cc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,7 +5,3 @@ import ( ) var RootCmd = &cobra.Command{} - -func SetVersion(version string) { - RootCmd.Version = version -} diff --git a/cmd/version.go b/cmd/version.go index 2bb8dc2..608c9ce 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "sub2sing-box/constant" "github.com/spf13/cobra" ) @@ -11,7 +12,7 @@ var versionCmd = &cobra.Command{ Short: "Print version", Long: "Print version", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("version: " + RootCmd.Version) + fmt.Println("version: " + constant.Version) }, } diff --git a/constant/version.go b/constant/version.go new file mode 100644 index 0000000..c8b5168 --- /dev/null +++ b/constant/version.go @@ -0,0 +1,3 @@ +package constant + +var Version = "dev" diff --git a/main.go b/main.go index 98cf883..408dbce 100644 --- a/main.go +++ b/main.go @@ -5,13 +5,6 @@ import ( "sub2sing-box/cmd" ) -var Version string - -func init() { - Version = "dev" - cmd.SetVersion(Version) -} - func main() { if err := cmd.RootCmd.Execute(); err != nil { fmt.Println(err)