Skip to content

feat: aligned version output and full shell completion - #23

Merged
boeboe merged 2 commits into
mainfrom
feat/version-completion
Nov 7, 2026
Merged

boeboe merged 2 commits into
mainfrom
feat/version-completion

Conversation

@boeboe

@boeboe boeboe commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What changed

version prints one line, aligned with the other OT Fabric CLIs, and one JSON object with --json (or SPARKPLUGBCTL_FORMAT=json):

  • Text: <name> <version> (tag <tag>, commit <sha>, built <date>, <go>, <goos>/<goarch>); the version has no leading v, the tag part is left out without a tag.
  • JSON keys, always present, in order: name, version, tag, commit, built, libraries, go, platform (documented in docs/json-output.md).
  • Libraries: every github.com/otfabric/go-* dependency from the build info (replacement version when replaced), sorted by name, shown after built … as go-sparkplugb 0.3.3; "libraries":[] in JSON when none.
  • New internal/buildinfo package. Fallbacks when nothing is injected: version from debug.ReadBuildInfo for a released go install …@vX.Y.Z (pseudo-versions and +dirty stamps of go build count as dev), commit from vcs.revision with -dirty, else dev/unknown.
  • ldflags: the release workflow and the Makefile add -X main.tag=${TAG}; the Makefile now injects the full commit SHA, and VERSION/TAG only when HEAD is exactly on a tag (otherwise dev). Variables stay main.version, main.commit, main.date.

Shell completion: completion covers bash, zsh, fish and PowerShell (cobra default). New value completion:

  • --metric (publish, edge, encode): after name: it completes the 15 metric types as name:<Type>=.
  • --tls-cert, --tls-ca: .pem/.crt/.cer files; --tls-key: .pem/.key files.
  • decode --file, encode --file: files.
  • All other value flags (--broker, --client-id, --username, --password, --group, --node, --device, --interval, --primary-host, --host-id, --topic, --seq) and every command's positional args: no file completion.

README: version section with the new output; one-sentence intro on the Shell completion subsection. RELEASE.md: v0.4.0 section.

Before / after

Before (make build on main):

sparkplugbctl v0.3.6-6-ga54bc2e
  commit:  a54bc2e
  built:   2026-11-07T21:39:02Z
  library: go-sparkplugb v0.3.3
  go:      go1.27.3
  os/arch: darwin/arm64

After (release-style ldflags):

sparkplugbctl 0.4.0 (tag v0.4.0, commit a54bc2e3e6f92470f0626dc6538645e891b5385e, built 2026-11-07T10:00:00Z, go-sparkplugb 0.3.3, go1.27.3, darwin/arm64)
{"name":"sparkplugbctl","version":"0.4.0","tag":"v0.4.0","commit":"a54bc2e3e6f92470f0626dc6538645e891b5385e","built":"2026-11-07T10:00:00Z","libraries":[{"name":"go-sparkplugb","version":"0.3.3"}],"go":"go1.27.3","platform":"darwin/arm64"}

After (go build, and make build off a tag):

sparkplugbctl dev (commit a54bc2e3e6f92470f0626dc6538645e891b5385e-dirty, built unknown, go-sparkplugb 0.3.3, go1.27.3, darwin/arm64)

Tests

  • internal/buildinfo: text with all fields, without tag, dev fallback, VCS fallback with -dirty, go install version, pseudo/dirty versions as dev, JSON key order and values, formatting with zero, one and two libraries (list injected), library selection from build info (main module, non-otfabric and replacements).
  • cmd: version text, --json, SPARKPLUGBCTL_FORMAT=json|text; __complete for the four shells, --metric types on all three commands, TLS file extensions, no-file directives; a walk that fails when a value flag has no completion function or a leaf command no ValidArgsFunction.
  • make check (fmt, staticcheck, golangci-lint, vet, govulncheck, -race tests, coverage gate 100%, per-package floor, docsync) and make e2e green locally; binary run for version, version --json, completion bash|zsh|fish|powershell and several __complete calls.

🤖 Generated with Claude Code

version prints one line, <name> <version> (tag <tag>, commit <sha>,
built <date>, <go>, <goos>/<goarch>), and one JSON object with --json or
SPARKPLUGBCTL_FORMAT=json. Missing build metadata falls back to the Go
build information (go install @vX.Y.Z, VCS revision with -dirty), then
to dev/unknown. The release workflow and Makefile inject the tag and
the full commit SHA.

Flag values complete: the metric type of --metric, certificate files
for the TLS flags, no file names for free-value flags and argument-less
commands. Tests cover __complete for all four shells and walk every
flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…builds

version lists the github.com/otfabric/go-* modules the binary is built
on after the build date (go-sparkplugb 0.3.3), and --json gains a
libraries array between built and go ([] when none). The Makefile
injects VERSION and TAG only when HEAD is exactly on a tag, so a
make build elsewhere reports dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boeboe
boeboe merged commit 3f78836 into main Nov 7, 2026
19 checks passed
@boeboe
boeboe deleted the feat/version-completion branch November 7, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant