From 0f1710b6c4f602c6f2b3bd5a625e1e7628fe44de Mon Sep 17 00:00:00 2001 From: iBug Date: Thu, 18 Jan 2024 05:51:04 +0800 Subject: [PATCH] Move version out of main.go --- cmd/root.go | 3 +-- cmd/version.go | 6 ++++++ main.go | 3 --- 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 cmd/version.go diff --git a/cmd/root.go b/cmd/root.go index 0b160cf..075cf83 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,13 +8,12 @@ import ( "github.com/spf13/cobra" ) -var Version string var versionCmd = &cobra.Command{ Use: "version", Short: "Show version", Hidden: true, Run: func(cmd *cobra.Command, args []string) { - cmd.Println(cmd.Root().Name(), Version) + cmd.Println(cmd.Root().Name(), version) }, } diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..94f3e51 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,6 @@ +package cmd + +import _ "unsafe" + +//go:linkname version main.version +var version string = "" diff --git a/main.go b/main.go index e7f8424..0b5493d 100644 --- a/main.go +++ b/main.go @@ -6,10 +6,7 @@ import ( "github.com/USTC-vlab/vct/cmd" ) -var version string = "" - func main() { - cmd.Version = version if err := cmd.MakeCmd().Execute(); err != nil { os.Exit(1) }