Skip to content

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

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

boeboe merged 3 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: sunspecctl <version> (tag <tag>, commit <sha>, built <date>, <go>, <goos>/<goarch>); the tag part is left out without a tag, the version has no leading v. A development build reports dev and takes the commit from the Go VCS stamp (-dirty for a modified tree); go install …@vX.Y.Z reports that version. New package internal/buildinfo; main.* stays the ldflags target.
  • version --json (the global --json, also SUNSPECCTL_FORMAT=json): one JSON line, keys name, version, tag, commit, built, go, platform in this order, always present. Breaking for scripts that read the old object (buildDate → built, indented → one line); noted in RELEASE.md and docs/json-output.md.
  • Completion: the own completion command keeps all four shells (bash now uses cobra's V2 script with descriptions). Every flag that takes a value now has a completion function (walk test): --parity, --data-bits, --stop-bits, --baud, --url (schemes), --id/--model (model IDs with a known schema, with labels), --point (point names of the --model given), serve --file (json), --tls-ca/--tls-cert/--tls-key (pem…), --output (any file); --timeout, --interval, --count, --unit-id, --base-address complete no file names. Commands without positional arguments complete no file names.
  • make build: COMMIT is the full SHA; TAG uses --exact-match (it used --abbrev=0, which stamped the last tag on any later commit). Release workflow ldflags were already correct.
  • README (completion sentence, command tree), docs/json-output.md, RELEASE.md v0.6.0, tests, e2e test.

Follow-up commit (brief amendments)

  • The OT Fabric libraries (github.com/otfabric/go-* modules of the build info, sorted) follow built … in the text line, and libraries ([{"name","version"}], [] when none) sits between built and go in the JSON.
  • Pseudo-versions and +dirty module versions report dev.
  • Makefile: VERSION and TAG only when HEAD is exactly on a tag; otherwise empty and the binary reports dev.

Before / after

Before (v0.5.1 built with release-style ldflags):

sunspecctl v0.5.1
tag:       v0.5.1
commit:    48b0eace00a40611e79cac3c5167b5ba6b9fd5a5
built:     2026-11-05T15:41:49Z
{
  "buildDate": "2026-11-05T15:41:49Z",
  "commit": "48b0eace00a40611e79cac3c5167b5ba6b9fd5a5",
  "tag": "v0.5.1",
  "version": "v0.5.1"
}

After (release-style ldflags):

sunspecctl 0.6.0 (tag v0.6.0, commit 48de6a31b3a9c25dee761756a43be67ad2052abc, built 2026-11-07T12:00:00Z, go-modbus 1.11.1, go-serial 0.2.1, go-sunspec 0.10.0, go1.27.3, darwin/arm64)
{"name":"sunspecctl","version":"0.6.0","tag":"v0.6.0","commit":"48de6a31b3a9c25dee761756a43be67ad2052abc","built":"2026-11-07T12:00:00Z","libraries":[{"name":"go-modbus","version":"1.11.1"},{"name":"go-serial","version":"0.2.1"},{"name":"go-sunspec","version":"0.10.0"}],"go":"go1.27.3","platform":"darwin/arm64"}

Plain go build (a clean checkout off a tag):

sunspecctl dev (commit 48de6a31b3a9c25dee761756a43be67ad2052abc, built unknown, go-modbus 1.11.1, go-serial 0.2.1, go-sunspec 0.10.0, go1.27.3, darwin/arm64)

Tests run

  • make check (fmt-check, vet, lint, vuln, race tests, coverage 99.0%), make e2e
  • Binary: version, version --json, SUNSPECCTL_FORMAT=json version, completion bash|zsh|fish|powershell, __complete completion "", __complete read-point --model 103 --point "", __complete detect --parity ""

🤖 Generated with Claude Code

version prints one line, name version (tag, commit, built, go, platform),
and version --json (or SUNSPECCTL_FORMAT=json) one JSON line with the
keys name, version, tag, commit, built, go, platform. A development
build falls back on the Go module version and VCS stamp.

Every flag that takes a value now has a completion function: serial
enums, URL schemes, model IDs and point names from the go-sunspec
registry, JSON and PEM files, no file names for free values. The bash
script is cobra's V2. make build stamps the full SHA and a tag only on
a tagged commit.

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

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.98496% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
completion.go 89.47% 3 Missing and 3 partials ⚠️
internal/buildinfo/buildinfo.go 96.92% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

boeboe and others added 2 commits November 7, 2026 23:02
version names the github.com/otfabric/go-* modules the binary is built
with after the build date, and version --json has a libraries array
between built and go. Pseudo-versions and +dirty versions from the build
info report dev. make build stamps VERSION and TAG only when HEAD is
exactly on a tag; otherwise the binary reports dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boeboe
boeboe merged commit 82c152f into main Nov 7, 2026
23 checks passed
@boeboe
boeboe deleted the feat/version-completion branch November 7, 2026 22:20
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