feat: add eko version command with runtime & git commit details - #184
Merged
Conversation
Adds an `eko version` subcommand and matching `-v` / `--version` root flags that report the CLI version, Go runtime version, target OS/arch, Git commit, and build date. - cmd/version.go: `versionCmd` plus the `Version`, `Commit` and `BuildDate` variables stamped via `-ldflags` at release time. A shared `formatVersion` helper renders the banner so the subcommand and the root flags cannot drift apart. - cmd/root.go: wires `Version` and a custom version template into the root command and registers the `-v` / `--version` flags. - .goreleaser.yaml: injects the release version, commit and date through the Go linker so published archives report real metadata. - Build metadata falls back to `dev` / `unknown` when it is not stamped (and when a linker flag injects an empty string), so a plain `go build` never prints blank fields. - cmd/commands_test.go: covers the banner format, the empty-metadata fallback, the subcommand, argument rejection, and `-v` / `--version` parity with the subcommand. - Documents the command in README.md and docs/docs/cli-reference.md. Closes kavix#78
|
@vsolano9 is attempting to deploy a commit to the Kavindu's projects Team on Vercel. A member of the Team first needs to authorize it. |
kavix
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds an
eko versionsubcommand and the matching-v/--versionflags on the root command. Both print the CLI version, target OS/architecture, Go runtime version, Git commit, and build date.What changed
cmd/version.go(new) — defines the CobraversionCmdand theVersion,Commit,BuildDatepackage variables that are stamped at release time via-ldflags. A singleformatVersionhelper renders the banner so the subcommand and the root flags can never drift apart.cmd/root.go— wiresVersionontorootCmd, sets a custom version template, and registers the-v/--versionflags. Keeping the flag wiring inroot.gomatches the issue's implementation steps and keeps root-command configuration in one place..goreleaser.yaml— injects the release version, commit, and date through the Go linker so published archives report real metadata instead ofdev.cmd/commands_test.go— unit/integration tests, added to the existing CLI test file as the issue specifies.README.md,docs/docs/cli-reference.md— document the command, the flags, and the ldflags build recipe.Why the
dev/unknowndefaultsThe variables default to
devandunknown, andformatVersionalso substitutes those placeholders if a linker flag injects an empty string. That means a plaingo build ./...(or theDockerfilebuild, which does not pass-Xflags) never prints blank fields. This is covered by a dedicated regression test.Note on
-v:-vwas previously free on the root command. It is already used as a subcommand-local shorthand ineko diff -v(--full) andeko history -v(--verbose); those are unaffected because the new flag is registered on the root command's own flag set, not as a persistent flag. Verified by the full test suite, which includes the existing diff/history tests.Related Issues
Closes #78
Type of Change
Technical Details & Architecture Notes
No concurrency or database changes. The only design decisions worth flagging:
formatVersion(version, commit, buildDate)is used both byversionCmd.RunEand byrootCmd.SetVersionTemplate(...), soeko version,eko -v, andeko --versionare byte-identical by construction. A test asserts that equality rather than trusting it.cmd.OutOrStdout(), matching the existing command style and making the subcommand testable through the repo's existingexecuteCommandtest helper.cobra.NoArgssoeko version extrafails loudly instead of silently ignoring input.-vshorthand is registered withrootCmd.Flags()(local), notPersistentFlags(), deliberately avoiding a collision with the existing-vshorthands oneko diffandeko history.How Has This Been Tested?
Automated tests added to
cmd/commands_test.go: banner formatting, empty-metadata fallback, default build metadata, the subcommand, argument rejection, and-v/--versionparity with the subcommand.gofmt(only the files touched by this PR; unrelated pre-existing files are untouched):$ gofmt -l cmd/version.go cmd/root.go cmd/commands_test.go $go build ./...andgo vet ./...:go test ./...(full suite):New tests, verbose:
Manual verification — un-stamped build (what a contributor's
go buildproduces):Manual verification — ldflags path, using the exact variable paths from
.goreleaser.yaml:Help output confirms discoverability:
Checklist
gofmtandgo vet)README.mdandCONTRIBUTING.md)One thing for a maintainer to confirm: the sample output in the issue shows three lines; this implementation adds a fourth,
Build date:, since the issue's implementation steps ask for aBuildDatevariable. Happy to drop that line from the banner (keeping the variable for GoReleaser) if you prefer to match the issue's sample exactly.