cli,doctor: --version flag + CLI/install drift check
Two pre-release polish items on the version-display surface.
* --version on both binaries: cobra's Version field on the banger
and bangerd roots renders a one-line summary (banger v0.1.0
(commit abcd1234, built 2026-04-28T20:45:50Z)). The
SetVersionTemplate override drops cobra's "{{.Name}} version"
prefix — our string is already a complete sentence. The
multi-line `banger version` subcommand is unchanged for callers
that want the full SHA / built_at on separate lines.
* Doctor "banger version" row: prints the running CLI's version +
short commit + built-at, plus what /etc/banger/install.toml
recorded at install time. Disagreement is the most common
version-skew pitfall (stale CLI against fresh daemon, or vice
versa) and a one-line warn is friendlier than tracking that down
from a launch failure.
Drift detection is suppressed when either side is dev/unknown
(untagged build) — comparing a dev CLI against a tagged install
is the developer-machine case, not a real problem.
formatVersionLine is in internal/cli (banger.go) and reused by
bangerd.go via a strings.Replace because bangerd's version line
should say "bangerd" not "banger". Slightly tilt-feeling but cheaper
than parameterising the helper for one caller.
Tests: TestVersionsDriftToleratesDevAndUnknown pins the four
branches (match, version diff, commit diff, dev-suppression). The
existing version-format test already runs through formatVersionLine
indirectly.
Live exercise:
$ banger --version
banger dev (commit 1c1ca7d6, built 2026-04-28T20:52:33Z)
$ bangerd --version
bangerd dev (commit 1c1ca7d6, built 2026-04-28T20:52:33Z)
$ banger doctor | head
...
PASS banger version
- CLI dev (commit 1c1ca7d6, built 2026-04-28T20:52:33Z)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1c1ca7d6a4
commit
775525b592
4 changed files with 121 additions and 2 deletions
|
|
@ -21,8 +21,9 @@ func NewBangerCommand() *cobra.Command {
|
|||
|
||||
func (d *deps) newRootCommand() *cobra.Command {
|
||||
root := &cobra.Command{
|
||||
Use: "banger",
|
||||
Short: "Run development sandboxes as Firecracker microVMs",
|
||||
Use: "banger",
|
||||
Version: formatVersionLine(buildinfo.Current()),
|
||||
Short: "Run development sandboxes as Firecracker microVMs",
|
||||
Long: strings.TrimSpace(`
|
||||
banger runs disposable development sandboxes as Firecracker microVMs.
|
||||
Each sandbox boots in a few seconds, gets its own root filesystem and
|
||||
|
|
@ -50,6 +51,9 @@ to diagnose host readiness problems.
|
|||
SilenceErrors: true,
|
||||
RunE: helpNoArgs,
|
||||
}
|
||||
// Drop cobra's default "{{.Name}} version {{.Version}}" wrapper —
|
||||
// our Version string is already a complete sentence.
|
||||
root.SetVersionTemplate("{{.Version}}\n")
|
||||
root.AddCommand(
|
||||
d.newDaemonCommand(),
|
||||
d.newDoctorCommand(),
|
||||
|
|
@ -186,3 +190,17 @@ func absolutizePaths(values ...*string) error {
|
|||
func formatBuildInfoBlock(info buildinfo.Info) string {
|
||||
return fmt.Sprintf("version: %s\ncommit: %s\nbuilt_at: %s\n", info.Version, info.Commit, info.BuiltAt)
|
||||
}
|
||||
|
||||
// formatVersionLine renders a buildinfo.Info as a single line —
|
||||
// "banger v0.1.0 (commit abcd1234, built 2026-04-28T20:45:50Z)" — for
|
||||
// the `--version` flag. Long commit strings are truncated to the
|
||||
// first 8 hex chars so the line stays scannable. The verbose
|
||||
// multi-line form lives on `banger version` for callers that want
|
||||
// the full SHA / built_at on separate lines.
|
||||
func formatVersionLine(info buildinfo.Info) string {
|
||||
commit := info.Commit
|
||||
if len(commit) > 8 {
|
||||
commit = commit[:8]
|
||||
}
|
||||
return fmt.Sprintf("banger %s (commit %s, built %s)", info.Version, commit, info.BuiltAt)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package cli
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"banger/internal/buildinfo"
|
||||
"banger/internal/daemon"
|
||||
"banger/internal/roothelper"
|
||||
|
||||
|
|
@ -14,6 +16,7 @@ func NewBangerdCommand() *cobra.Command {
|
|||
var rootHelperMode bool
|
||||
cmd := &cobra.Command{
|
||||
Use: "bangerd",
|
||||
Version: strings.Replace(formatVersionLine(buildinfo.Current()), "banger ", "bangerd ", 1),
|
||||
Short: "Run the banger daemon",
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
|
|
@ -44,6 +47,7 @@ func NewBangerdCommand() *cobra.Command {
|
|||
}
|
||||
cmd.Flags().BoolVar(&systemMode, "system", false, "run as the owner-user system service")
|
||||
cmd.Flags().BoolVar(&rootHelperMode, "root-helper", false, "run as the privileged root helper service")
|
||||
cmd.SetVersionTemplate("{{.Version}}\n")
|
||||
cmd.CompletionOptions.DisableDefaultCmd = true
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue