feat(cli): enhance version command output#108
Conversation
|
🚀 First PR — welcome aboard! A few things to expect:
If you get stuck, reply here or jump to Discussions. We want this PR to land. |
|
Hello @btwshivam and @oksaumya after many attempts. I have fixed the pr and made sure that there are no unnecessary changes. Kindly review my PR and let me know |
Signed-off-by: Santosh <180573785+SANTOSH069@users.noreply.github.com>
8a9fd1a to
53fc775
Compare
|
Hello @btwshivam Can you PLEASE REVIEW MY PR ?! I have been waiting for your feedback. Kindly respond. |
|
Hello @btwshivam Can you please review my pull request. I would really like to know if this pr is going in the right direction or not .Let me know if there are any changes needed |
|
@SANTOSH069 sorry for delay.. will review all pRS on this weekends |
|
Hello @btwshivam can you please review my PR. Do let me know if there are any changes. |
btwshivam
left a comment
There was a problem hiding this comment.
version_tes.go isn't a _test.go file, so those tests never run and testing links into the prod binary. plus a dropped license header, a removed go-install version fallback, and renamed json fields. details inline.
| @@ -0,0 +1,51 @@ | |||
| package cli | |||
There was a problem hiding this comment.
this is version_tes.go, not version_test.go, so go doesn't treat it as a test file. the two Test* funcs never run under go test (that's why ci is green without exercising them), and testing gets compiled into the production cli package. importing testing into a real binary also registers the -test.* flags on the default flag set. rename to version_test.go.
| // Copyright 2026 Optiqor contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cli |
There was a problem hiding this comment.
the // Copyright / // SPDX-License-Identifier: Apache-2.0 header was dropped from this file, and the new version_tes.go never had one. every source file in the repo carries it. put both back.
| return fmt.Sprintf("kerno %s", i.Version) | ||
| } | ||
|
|
||
| func init() { |
There was a problem hiding this comment.
removing this init() is a regression. it's the debug.ReadBuildInfo() fallback that fills Version/Commit/Date when the binary is built without ldflags, e.g. go install github.com/optiqor/kerno/cmd/kerno@latest. without it, go install builds report version dev, commit none instead of the module version. #4 is about adding metadata, not dropping the install-time source of it. keep the fallback.
| GoVersion string `json:"goVersion"` | ||
| OS string `json:"os"` | ||
| Arch string `json:"arch"` | ||
| Date string `json:"built"` |
There was a problem hiding this comment.
these tags rename existing json fields: date to built, goVersion to go, and os/arch are dropped for a combined platform. anyone parsing kerno version --output json today breaks. if the rename is intentional, say so, otherwise keep date/goVersion/os/arch and add platform alongside.
| } | ||
|
|
||
| cmd.Flags().BoolVar(&short, "short", false, "Print only the version number") | ||
| cmd.Flags().StringVarP(&output, "output", "o", "text", "Output format: text or json") |
There was a problem hiding this comment.
root already defines a persistent --output (root.go:72, default pretty, values pretty/json). this adds a second local --output with a different default (text) and a -o shorthand, so version diverges from every other command, and the old code that read the inherited flag is gone. reuse the inherited --output and just add --short, or at least match the pretty/json contract.
What
Enhances the
kerno versioncommand to display detailed build metadata including commit hash, build date, Go version, and platform information.Adds support for:
--shortflag for scripting-friendly version output--output jsonfor structured JSON outputWhy
Fixes #4
How
Info.String()formatting to match the required multiline version outputInfo.Short()method through Cobra CLI flagskerno version --output jsonruntime.Version,runtime.GOOS,runtime.GOARCH) for platform informationTesting
go test ./internal/version -vpassesTested locally with:
go run ./cmd/kerno versiongo run ./cmd/kerno version --shortgo run ./cmd/kerno version --output jsongo run -ldflagsN/A — pure docs/refactor
Checklist
feat(scope): subject)git commit -s)