diff --git a/.woodpecker.yml b/.woodpecker.yml index 6c30f1d..1a8200f 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -15,8 +15,8 @@ pipeline: image: golang:1.16 commands: - go mod vendor - - GOOS=linux GOARCH=amd64 go build -o "dist/adept-linux-amd64-${CI_COMMIT_TAG}" - - GOOS=windows GOARCH=amd64 go build -o "dist/adept-windows-amd64-${CI_COMMIT_TAG}.exe" + - GOOS=linux GOARCH=amd64 go build -ldflags "-X git.metaunix.net/BitGoblin/adept/cmd.version=${CI_COMMIT_TAG}" -o "dist/adept-linux-amd64-${CI_COMMIT_TAG}" + - GOOS=windows GOARCH=amd64 go build -ldflags "-X git.metaunix.net/BitGoblin/adept/cmd.version=${CI_COMMIT_TAG}" -o "dist/adept-windows-amd64-${CI_COMMIT_TAG}.exe" when: event: tag diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..1bb283d --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "log" + "runtime" + + "github.com/spf13/cobra" +) + +var ( + version string +) + +// initializes the sub-command +func init() { + rootCmd.AddCommand(versionCmd) +} + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Display version info.", + Long: `In case you're curious, run this command to find out the version info.`, + Run: func(cmd *cobra.Command, args []string) { + log.Printf("Adept version %s", version) + log.Printf("Built with Go %s", runtime.Version()) + log.Printf("View source at https://git.metaunix.net/BitGoblin/adept") + }, +}