Skip to content

Commit

Permalink
also inject the gitcommit hash and the build time for more detailed v…
Browse files Browse the repository at this point in the history
…ersion information
  • Loading branch information
ftl committed Apr 2, 2021
1 parent c2141d1 commit 0ad0eb4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
OUT := hamdeck
VERSION?=$(shell echo `git rev-parse --abbrev-ref HEAD`-`git rev-parse --verify --short HEAD`)
VERSION?=$(shell echo development@`git rev-parse --abbrev-ref HEAD`-`git rev-parse --verify --short HEAD`)
GITCOMMIT=$(shell git rev-parse --verify --short HEAD)
BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")

all: test build
.PHONY: all

build:
go build -v -o $(OUT) -ldflags "-X github.com/ftl/hamdeck/cmd.version=$(VERSION)" .
go build -v -o $(OUT) -ldflags "-X github.com/ftl/hamdeck/cmd.version=$(VERSION) -X github.com/ftl/hamdeck/cmd.gitCommit=$(GITCOMMIT) -X github.com/ftl/hamdeck/cmd.buildTime=$(BUILDTIME)" .
.PHONY: build

test:
Expand Down
8 changes: 6 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import (
"github.com/ftl/hamdeck/pkg/tci"
)

var version string = "develop"
var (
version string = "development"
gitCommit string = "unknown"
buildTime string = "unknown"
)

var rootFlags = struct {
syslog bool
Expand Down Expand Up @@ -52,7 +56,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&rootFlags.serial, "serial", "", "the serial number of the Stream Deck device that should be used")
rootCmd.PersistentFlags().IntVar(&rootFlags.brightness, "brightness", 100, "the initial brightness of the Stream Deck device")
rootCmd.PersistentFlags().StringVar(&rootFlags.configFile, "config", "", "the configuration file that should be used (default: .config/hamradio/hamdeck.json)")
rootCmd.PersistentFlags().StringVar(&rootFlags.hamlibAddress, "hamlib", "", "the address of the rigctld server (if empty, hamlib buttons are not available")
rootCmd.PersistentFlags().StringVar(&rootFlags.hamlibAddress, "hamlib", "", "the address of the rigctld server (if empty, hamlib buttons are not available)")
rootCmd.PersistentFlags().StringVar(&rootFlags.tciAddress, "tci", "", "the address of the TCI server (if empty, tci buttons are not available)")
rootCmd.PersistentFlags().StringVar(&rootFlags.mqttAddress, "mqtt", "", "the address of the MQTT server (if empty, atu100 buttons are not available)")
rootCmd.PersistentFlags().StringVar(&rootFlags.mqttUsername, "mqttusername", "", "the username for MQTT")
Expand Down
21 changes: 21 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show version information",
Run: runVersion,
}

func init() {
rootCmd.AddCommand(versionCmd)
}

func runVersion(cmd *cobra.Command, args []string) {
fmt.Printf("Hamdeck Version %s %s %s\n", version, gitCommit, buildTime)
}

0 comments on commit 0ad0eb4

Please sign in to comment.