Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
Christopher Boone avatar

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-plugins

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
repo stars2
Last updatedJuly 24, 2026
Repositorycboone/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 commit and date variables to cmd/root.go alongside version, exposing a SetVersionInfo(v, c, d string) helper. If only SetVersion exists, it is replaced.
  • Detects the root command variable in package cmd and uses that identifier when registering the generated version subcommand.
  • Adds commit and date package-level vars to main.go and updates the call to cmd.SetVersionInfo.
  • Extends GoReleaser ldflags to include -X main.commit={{.ShortCommit}} and -X main.date={{.Date}}.
  • Extends the Makefile LDFLAGS to include matching -X entries plus COMMIT and DATE variables.

Examples

  • "add a version subcommand to this CLI": detects state and wires everything up
  • "wire up version, commit, and date ldflags": same behavior
  • "add --json to the version command": same behavior, ensures the --json flag is present

See Also

Related skills

Gobackend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.