feat(cli): add version diagnostics and build-aware start
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// Package version exposes host CLI build identity without requiring an installation descriptor.
|
||||
package version
|
||||
|
||||
import "runtime"
|
||||
|
||||
var (
|
||||
semanticVersion = "0.0.0-dev"
|
||||
commit = "unknown"
|
||||
buildTime = "unknown"
|
||||
)
|
||||
|
||||
// Info is the stable, machine-readable identity of the host-side CLI.
|
||||
type Info struct {
|
||||
Version string `json:"version"`
|
||||
Commit string `json:"commit"`
|
||||
BuildTime string `json:"buildTime"`
|
||||
OS string `json:"os"`
|
||||
Arch string `json:"arch"`
|
||||
}
|
||||
|
||||
// Current returns linker-overridable build metadata plus the executing host platform.
|
||||
func Current() Info {
|
||||
return Info{
|
||||
Version: semanticVersion,
|
||||
Commit: commit,
|
||||
BuildTime: buildTime,
|
||||
OS: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Catches a source build that reports no usable identity or the wrong host platform.
|
||||
func TestCurrentReportsUsableSourceBuildIdentity(t *testing.T) {
|
||||
info := Current()
|
||||
if info.Version == "" || info.Commit == "" || info.BuildTime == "" {
|
||||
t.Fatalf("Current() = %#v, want non-empty build identity", info)
|
||||
}
|
||||
if info.OS != runtime.GOOS || info.Arch != runtime.GOARCH {
|
||||
t.Fatalf("Current() platform = %s/%s, want %s/%s", info.OS, info.Arch, runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user