feat!: introduce ChronoTomatoVersion
- set version from `runtime/debug.Main.Version` - use latest git tag as fallback - allow version to be overwritten via ldflags - this will break `go build .` and `go install .`
This commit is contained in:
parent
58d658be66
commit
712aced7da
2 changed files with 42 additions and 0 deletions
|
@ -2,8 +2,11 @@ package client
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/helper"
|
||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/metadata"
|
||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
|
||||
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
|
@ -68,9 +71,15 @@ func Start() {
|
|||
parameter_url = flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)")
|
||||
parameter_password = flag.String("password", "", "Control password for pomodoro session")
|
||||
parameter_configfile = flag.String("config", defaultConfigFile, "Path to config file")
|
||||
showVersion = flag.Bool("version", false, "Show Version")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
if *showVersion {
|
||||
fmt.Printf("ChronoTomato v%v\n", metadata.ChronoTomatoVersion)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// read passed config file or try to use default config
|
||||
if *parameter_configfile != defaultConfigFile {
|
||||
config = helper.ParseConfig(*parameter_configfile)
|
||||
|
|
33
internal/metadata/version.go
Normal file
33
internal/metadata/version.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package metadata
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ChronoTomatoVersion = "" // The GoTomato version
|
||||
|
||||
func stripVersionPrefix(version string) string {
|
||||
return strings.TrimLeft(version, "v")
|
||||
}
|
||||
|
||||
func getLatestTag() string {
|
||||
bytes, _ := exec.Command("git", "describe", "--tags").Output()
|
||||
output := strings.TrimSpace(string(bytes))
|
||||
return stripVersionPrefix(output)
|
||||
}
|
||||
|
||||
// set GoTomatoVersion from runtime/debug.Main.Version
|
||||
// use latest git tag as fallback
|
||||
// can be overwritten via ldflags (e,g. by goreleaser)
|
||||
func init() {
|
||||
if ChronoTomatoVersion == "" {
|
||||
info, _ := debug.ReadBuildInfo()
|
||||
if info.Main.Version != "(devel)" {
|
||||
ChronoTomatoVersion = stripVersionPrefix(info.Main.Version)
|
||||
} else {
|
||||
ChronoTomatoVersion = getLatestTag()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue