Skip to content

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

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: modbusctl <version> (tag <tag>, commit <sha>, built <date>, <go>, <goos>/<goarch>). The tag part is left out when the build has no 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 (new flag) and MODBUSCTL_FORMAT=json: one JSON object, keys name, version, tag, commit, built, go, platform in this order, always present. MODBUSCTL_FORMAT=text|table print the text line.
  • Completion: completion already offered bash, zsh, fish and PowerShell (tested via __complete). Every flag that takes a value now has a completion function (a walk test fails otherwise). New value completion: --function of the capture commands (0-4), --missing, --before-first, --retry-timeout, --data-bits, --stop-bits, --baud, --family and --value-kind (from the codec registry), --url (schemes), --interface (network interfaces); file completion by extension for --input (mbcap/jsonl/csv), --profile/--blocks-file (json), --tls-ca/--tls-cert/--tls-key (pem…); --output completes any file; numbers, durations and addresses complete no file names. Commands without positional arguments complete no file names.
  • make build: COMMIT is the full SHA. Release workflow ldflags were already correct (-X main.version/tag/commit/buildDate).
  • README (version section, completion sentence), docs/json-output.md (version object), RELEASE.md v3.6.0, 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 (archive names fall back to dev).

Before / after

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

modbusctl version: v3.5.1
tag:         v3.5.1
commit:      1802d0f9afe8642d1e278120b76fcdfac967cb9e
build date:  2026-11-05T15:41:49Z

(version --json: error: unknown flag: --json)
After (release-style ldflags):

modbusctl 3.6.0 (tag v3.6.0, commit ae76784522f7853b6f19326b2b30bd6b92636e10, built 2026-11-07T12:00:00Z, go-modbus 1.11.1, go-modbus-capture 0.1.0, go-serial 0.2.1, go1.27.3, darwin/arm64)
{"name":"modbusctl","version":"3.6.0","tag":"v3.6.0","commit":"ae76784522f7853b6f19326b2b30bd6b92636e10","built":"2026-11-07T12:00:00Z","libraries":[{"name":"go-modbus","version":"1.11.1"},{"name":"go-modbus-capture","version":"0.1.0"},{"name":"go-serial","version":"0.2.1"}],"go":"go1.27.3","platform":"darwin/arm64"}

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

modbusctl dev (commit ae76784522f7853b6f19326b2b30bd6b92636e10, built unknown, go-modbus 1.11.1, go-modbus-capture 0.1.0, go-serial 0.2.1, go1.27.3, darwin/arm64)

Tests run

  • make check (fmt-check, vet, staticcheck, golangci-lint, govulncheck, tests, coverage 96.5%), make e2e, go test -race ./cmd/... ./internal/buildinfo
  • Binary: version, version --json, MODBUSCTL_FORMAT=json version, completion bash|zsh|fish|powershell, __complete completion "", __complete capture decode --input "", __complete server replay --missing "", __complete client read --url t

🤖 Generated with Claude Code

version prints one line, name version (tag, commit, built, go, platform),
and version --json (or MODBUSCTL_FORMAT=json) one JSON object 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: enum
values, file extensions for input files, URL schemes, interfaces, and
no file names for free values. make build stamps the full commit SHA.

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.84615% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/flag_completion.go 84.00% 8 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 bb0248f 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