feat: add --version flag with build metadata injection

Supports `goupkeep version`, `--version`, and `-v`. Prints version,
commit hash, and build date when injected via ldflags. Shows "dev"
for local builds. Dockerfile updated with ARGs for version injection.
This commit is contained in:
2026-05-24 14:14:13 -04:00
parent cc8d76fdbc
commit 8f9210b451
2 changed files with 21 additions and 1 deletions
+17
View File
@@ -27,6 +27,12 @@ import (
"github.com/mattn/go-isatty"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
log.SetOutput(os.Stderr)
@@ -38,11 +44,22 @@ func main() {
case "export":
runExport(os.Args[2:])
return
case "version", "--version", "-v":
printVersion()
return
}
}
runServe(os.Args[1:])
}
func printVersion() {
if version == "dev" {
fmt.Println("go-upkeep dev")
} else {
fmt.Printf("go-upkeep %s (%s, %s)\n", version, commit, date)
}
}
func envOrDefault(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v