
Add Cobra Version
- 2 repo stars
- Updated July 24, 2026
- cboone/agent-harness-plugins
Add a version subcommand with build metadata (version, commit, date, Go runtime, optional JSON) to a Cobra Go CLI, wiring ldflags across main.go, cmd, GoReleaser, and Makefile.
About
Add-cobra-version adds a version subcommand to an existing Cobra-based Go CLI, surfacing build metadata: version, commit hash, build date, Go runtime version, and optional JSON output. It wires the ldflags through main.go, the cmd package, GoReleaser, and the Makefile so the data is injected at build time. A Go implementation skill for CLI tooling.
- Cobra version subcommand
- Embeds version, commit, date, Go runtime
- Optional JSON output
- Wires ldflags in GoReleaser and Makefile
Add Cobra Version by the numbers
- Data as of Jul 25, 2026 (Skillselion catalog sync)
/plugin marketplace add cboone/agent-harness-plugins/plugin install add-cobra-version@agent-harness-pluginsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| repo stars | ★ 2 |
|---|---|
| Last updated | July 24, 2026 |
| Repository | cboone/agent-harness-plugins ↗ |
What it does
Add a version subcommand with build metadata (version, commit, date, Go runtime, optional JSON) to a Cobra Go CLI, wiring ldflags across main.go, cmd, GoReleaser, and Makefile.
README.md
Add Cobra Version
Add a version subcommand with full build metadata to an existing Cobra-based Go CLI.
Type: Skill
Trigger: /add-cobra-version
Installation
See the marketplace install instructions.
What It Does
Generates a cmd/version.go and coordinates the matching ldflags wiring across main.go, cmd/root.go, .goreleaser.yml, and the Makefile so a Cobra CLI can report:
- Version (from git tag, falling back to
"dev") - Commit hash (short)
- Build date (UTC, ISO 8601)
- Go runtime version (from
runtime.Version())
Output is human-readable by default with an optional --json flag for scripts. Cobra's built-in --version flag continues to work and reports the same version string.
Usage
/add-cobra-version
The skill detects the project's existing version wiring (basic var version only versus full version/commit/date) and then:
- Adds
cmd/version.go(skips or asks before overwriting if one already exists). - Adds package-level
commitanddatevariables tocmd/root.goalongsideversion, exposing aSetVersionInfo(v, c, d string)helper. If onlySetVersionexists, it is replaced. - Detects the root command variable in
package cmdand uses that identifier when registering the generatedversionsubcommand. - Adds
commitanddatepackage-level vars tomain.goand updates the call tocmd.SetVersionInfo. - Extends GoReleaser
ldflagsto include-X main.commit={{.ShortCommit}}and-X main.date={{.Date}}. - Extends the Makefile
LDFLAGSto include matching-Xentries plusCOMMITandDATEvariables.
Examples
- "add a version subcommand to this CLI": detects state and wires everything up
- "wire up version, commit, and date ldflags": same behavior
- "add
--jsonto the version command": same behavior, ensures the--jsonflag is present
See Also
- Scaffold Go CLI: scaffolding a brand-new Go CLI (starts with the basic
versionvariable). - Add GoReleaser Homebrew: adding GoReleaser and the release workflow when those are missing too.
- All plugins