diff --git a/.goreleaser.yml b/.goreleaser.yml index 9a1bcc4..2f3c2f9 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -18,6 +18,9 @@ builds: - "-s" - "-w" - "-extldflags '-static'" + - "-X go.xsfx.dev/wg-quicker/cmd.version={{.Version}}" + - "-X go.xsfx.dev/wg-quicker/cmd.commit={{.ShortCommit}}" + - "-X go.xsfx.dev/wg-quicker/cmd.date={{.Date}}" hooks: pre: - make clean diff --git a/cmd/root.go b/cmd/root.go index 366f1fe..e850b3f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( + "fmt" "io/ioutil" "os" @@ -10,6 +11,12 @@ import ( "go.xsfx.dev/wg-quicker/wgquick" ) +var ( + version = "dev" + commit = "none" + date = "unknown" +) + var ( iface string verbose bool @@ -33,6 +40,14 @@ var rootCmd = &cobra.Command{ }, } +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print version informations", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("wg-quicker %s, commit %s, build on %s", version, commit, date) // nolint: forbidigo + }, +} + var upCmd = &cobra.Command{ Use: "up [ config_file | interface ]", Short: "Bringing interface up", @@ -117,6 +132,7 @@ func init() { rootCmd.AddCommand(upCmd) rootCmd.AddCommand(downCmd) rootCmd.AddCommand(syncCmd) + rootCmd.AddCommand(versionCmd) } func Execute() {