Skip to content

feat(cli): enhance version command output#108

Open
SANTOSH069 wants to merge 1 commit into
optiqor:mainfrom
SANTOSH069:feat/version-clean
Open

feat(cli): enhance version command output#108
SANTOSH069 wants to merge 1 commit into
optiqor:mainfrom
SANTOSH069:feat/version-clean

Conversation

@SANTOSH069
Copy link
Copy Markdown

What

Enhances the kerno version command to display detailed build metadata including commit hash, build date, Go version, and platform information.

Adds support for:

  • --short flag for scripting-friendly version output
  • --output json for structured JSON output

Why

Fixes #4

How

  • Updated Info.String() formatting to match the required multiline version output
  • Exposed the existing Info.Short() method through Cobra CLI flags
  • Added JSON output formatting support for kerno version --output json
  • Added and updated tests for short output and version formatting behavior
  • Used Go runtime metadata (runtime.Version, runtime.GOOS, runtime.GOARCH) for platform information

Testing

  • go test ./internal/version -v passes

  • Tested locally with:

    • go run ./cmd/kerno version
    • go run ./cmd/kerno version --short
    • go run ./cmd/kerno version --output json
    • ldflags injection testing using go run -ldflags
  • N/A — pure docs/refactor

Checklist

  • PR title follows Conventional Commits (feat(scope): subject)
  • All commits are DCO-signed (git commit -s)
  • No unrelated changes pulled in
  • Documentation updated where user-visible behavior changed
  • Added/updated tests for new code paths

@SANTOSH069 SANTOSH069 requested a review from btwshivam as a code owner May 27, 2026 16:46
@github-actions
Copy link
Copy Markdown

🚀 First PR — welcome aboard!

A few things to expect:

  1. CI: every PR runs build + race tests + lint + (eventually) the kernel matrix. If something fails, the log will tell you exactly which gate.
  2. DCO: every commit needs Signed-off-by:git commit -s adds it automatically.
  3. Conventional Commits: PR titles like feat(doctor): add new rule or fix(bpf): handle X. We squash-merge by default.
  4. Review: a maintainer will review within 72 hours. Suggestions are conversations, not orders — push back if something doesn't fit your context.

If you get stuck, reply here or jump to Discussions. We want this PR to land.

@github-actions github-actions Bot added level:advanced 200+ lines or 6+ files (auto-applied) testing Tests and test coverage labels May 27, 2026
@SANTOSH069
Copy link
Copy Markdown
Author

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>
@SANTOSH069 SANTOSH069 force-pushed the feat/version-clean branch from 8a9fd1a to 53fc775 Compare May 27, 2026 16:50
@SANTOSH069
Copy link
Copy Markdown
Author

Hello @btwshivam Can you PLEASE REVIEW MY PR ?! I have been waiting for your feedback. Kindly respond.

@SANTOSH069
Copy link
Copy Markdown
Author

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

@btwshivam
Copy link
Copy Markdown
Member

@SANTOSH069 sorry for delay.. will review all pRS on this weekends

@SANTOSH069
Copy link
Copy Markdown
Author

Hello @btwshivam can you please review my PR. Do let me know if there are any changes.

Copy link
Copy Markdown
Member

@btwshivam btwshivam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on it @btwshivam

Comment thread internal/cli/version.go
// Copyright 2026 Optiqor contributors
// SPDX-License-Identifier: Apache-2.0

package cli
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/cli/version.go
}

cmd.Flags().BoolVar(&short, "short", false, "Print only the version number")
cmd.Flags().StringVarP(&output, "output", "o", "text", "Output format: text or json")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:advanced 200+ lines or 6+ files (auto-applied) testing Tests and test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance kerno version with build metadata (commit, date, Go version)

2 participants