diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3b65e4f..9a31e33 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,9 +1,16 @@ builds: - - targets: + - + targets: - linux_amd64 - windows_amd64 - darwin_amd64 - darwin_arm64 + ldflags: + - > + -s -w + -X github.com/leancodepl/poe2arb/cmd.Version={{.Version}} + -X github.com/leancodepl/poe2arb/cmd.Commit={{.Commit}} + -X github.com/leancodepl/poe2arb/cmd.BuiltDate={{.Date}} universal_binaries: - replace: true changelog: diff --git a/cmd/poe2arb.go b/cmd/poe2arb.go index f7c8a13..d760f7f 100644 --- a/cmd/poe2arb.go +++ b/cmd/poe2arb.go @@ -11,6 +11,7 @@ var rootCmd = &cobra.Command{ func Execute() { rootCmd.AddCommand(convertCmd) rootCmd.AddCommand(poeCmd) + rootCmd.AddCommand(versionCmd) rootCmd.Execute() } diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..22e772d --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,24 @@ +package cmd + +import "github.com/spf13/cobra" + +var ( + // Version is the version of the application. It is set during the build process using ldflags. + Version = "dev" + // Commit is the commit hash of the application. It is set during the build process using ldflags. + Commit = "none" + // Date is the date of the build. It is set during the build process using ldflags. + BuiltDate = "unknown" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the version number of poe2arb", + RunE: runVersion, +} + +func runVersion(cmd *cobra.Command, args []string) error { + cmd.Printf("poe2arb version %s, commit %s, built at %s\n", Version, Commit, BuiltDate) + + return nil +}