feat: IMP-13 — add version command with build-time variables

opal version (and opal --version) prints version, commit, and build
date. Values are set via ldflags at build time; defaults to "dev" for
local builds. VERSION file added at 0.1.0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-19 13:38:25 +01:00
parent f57baee6bc
commit 779da6ddfd
3 changed files with 34 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// Set via ldflags at build time:
//
// go build -ldflags "-X git.jnss.me/joakim/opal/cmd.Version=$(cat VERSION)
// -X git.jnss.me/joakim/opal/cmd.Commit=$(git rev-parse --short HEAD)
// -X git.jnss.me/joakim/opal/cmd.BuildDate=$(date -u +%Y-%m-%d)"
var (
Version = "dev"
Commit = "unknown"
BuildDate = "unknown"
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("opal %s (%s) built %s\n", Version, Commit, BuildDate)
},
}