779da6ddfd
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>
27 lines
598 B
Go
27 lines
598 B
Go
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)
|
|
},
|
|
}
|