Conversation
Reviewer's GuideAdds build date metadata to the lets binary, wires it through the root command via Cobra annotations, adjusts build tooling to set it via ldflags, and updates tests to validate the new version output format. Sequence diagram for version command with BuildDate annotationsequenceDiagram
actor User
participant Shell
participant Main as main
participant CmdPkg as internal_cmd
participant RootCmd as cobra_Command
User->>Shell: lets --version
Shell->>Main: start process
Main->>CmdPkg: CreateRootCommand(Version, BuildDate)
CmdPkg->>RootCmd: newRootCmd(Version)
CmdPkg->>RootCmd: set Annotations[buildDate] = BuildDate
CmdPkg-->>Main: *cobra_Command
Main->>RootCmd: Execute()
RootCmd->>RootCmd: detect --version flag
RootCmd->>CmdPkg: PrintVersionMessage(cmd)
CmdPkg->>CmdPkg: msg = sprintf("lets version %s", cmd.Version)
CmdPkg->>CmdPkg: buildDate = cmd.Annotations[buildDate]
CmdPkg->>CmdPkg: if buildDate != "" then append " (buildDate)"
CmdPkg->>RootCmd: Fprintln(cmd.OutOrStdout(), msg)
RootCmd-->>User: print version with optional build date
Class diagram for main and root command with BuildDateclassDiagram
class main {
+string Version
+string BuildDate
+main()
-getContext() Context
}
class internal_cmd_Root {
+CreateRootCommand(version string, buildDate string) *cobra_Command
+PrintRootHelpMessage(cmd *cobra_Command) error
+PrintVersionMessage(cmd *cobra_Command) error
-newRootCmd(version string) *cobra_Command
-initRootFlags(cmd *cobra_Command)
}
class cobra_Command {
+string Version
+map~string,string~ Annotations
+io_Writer OutOrStdout()
+Execute() error
}
main --> internal_cmd_Root : calls CreateRootCommand
internal_cmd_Root --> cobra_Command : constructs and configures
cobra_Command ..> internal_cmd_Root : uses PrintVersionMessage for --version
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
5f20567 to
20743cb
Compare
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="internal/cmd/root_test.go" line_range="14" />
<code_context>
func newTestRootCmd(args []string) (rootCmd *cobra.Command) {
- root := CreateRootCommand("v0.0.0-test")
+ root := CreateRootCommand("v0.0.0-test", "")
root.SetArgs(args)
InitCompletionCmd(root, nil)
</code_context>
<issue_to_address>
**suggestion (testing):** Add a unit test covering PrintVersionMessage with a non-empty build date
Right now all Go tests call `CreateRootCommand` with an empty build date, so the code path that formats `"lets version %s (%s)"` is only exercised by Bats. Please add a unit test that constructs a root command with a non-empty build date (e.g. `CreateRootCommand("v0.0.0-test", "2024-01-15T10:30:00Z")`), calls `PrintVersionMessage`, and asserts the output includes the date in parentheses.
Suggested implementation:
```golang
)
func TestPrintVersionMessage_WithBuildDate(t *testing.T) {
bufOut := &bytes.Buffer{}
root := CreateRootCommand("v0.0.0-test", "2024-01-15T10:30:00Z")
root.SetOut(bufOut)
PrintVersionMessage(root)
got := bufOut.String()
expectedSubstring := "lets version v0.0.0-test (2024-01-15T10:30:00Z)"
if !strings.Contains(got, expectedSubstring) {
t.Fatalf("expected version output %q to contain %q", got, expectedSubstring)
}
}
```
```golang
import (
"bytes"
"strings"
```
Because I can only see part of `internal/cmd/root_test.go`, please double-check:
1. The `import` block: ensure `bytes` and `strings` are not already imported to avoid duplicates. If `import (` already exists with other imports, merge these two into that block instead of creating a new one.
2. The function name `PrintVersionMessage` and its signature: if it requires additional parameters (e.g. context or writer), adapt the test to call it correctly while still setting `root.SetOut(bufOut)` so the message is captured in `bufOut`.
3. If the existing tests construct the root command or capture output in a helper (e.g. `newTestRootCmd` or a shared `bufOut`), you may want to reuse that helper to be consistent with the rest of the test suite.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Greptile SummaryThis PR adds a Key changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant main as cmd/lets/main.go
participant root as internal/cmd/root.go
Note over main: var Version = "0.0.0-dev"<br/>var BuildDate = "" (or injected via ldflags)
main->>root: CreateRootCommand(Version, BuildDate)
root->>root: newRootCmd(version)
root->>root: rootCmd.Annotations["buildDate"] = buildDate
root-->>main: rootCmd
User->>main: lets --version
main->>root: PrintVersionMessage(rootCmd)
root->>root: msg = "lets version " + cmd.Version
alt buildDate != ""
root->>root: msg += " (" + buildDate + ")"
end
root-->>User: "lets version 1.2.3 (2024-01-15T10:30:00Z)"
Last reviewed commit: 20743cb |
| go build -ldflags="-X main.Version=${TEST_VERSION} -X main.BuildDate=${TEST_BUILD_DATE}" -o /tmp/lets-version-test cmd/lets/main.go | ||
| run /tmp/lets-version-test --version | ||
| assert_success | ||
| assert_line --index 0 "lets version ${TEST_VERSION} (${TEST_BUILD_DATE})" | ||
| rm -f /tmp/lets-version-test |
There was a problem hiding this comment.
Hardcoded /tmp path may fail in parallel CI runs
The test binary is written to /tmp/lets-version-test, a shared path across all processes. If this test suite runs concurrently (e.g., multiple CI jobs on the same runner), two jobs could race on the same file — one deleting it while the other is trying to use it, or one overwriting the binary during another's execution.
Consider using a unique temp path, such as one derived from $BATS_TMPDIR (provided by the BATS framework), which is isolated per test run:
| go build -ldflags="-X main.Version=${TEST_VERSION} -X main.BuildDate=${TEST_BUILD_DATE}" -o /tmp/lets-version-test cmd/lets/main.go | |
| run /tmp/lets-version-test --version | |
| assert_success | |
| assert_line --index 0 "lets version ${TEST_VERSION} (${TEST_BUILD_DATE})" | |
| rm -f /tmp/lets-version-test | |
| go build -ldflags="-X main.Version=${TEST_VERSION} -X main.BuildDate=${TEST_BUILD_DATE}" -o "${BATS_TMPDIR}/lets-version-test" cmd/lets/main.go | |
| run "${BATS_TMPDIR}/lets-version-test" --version | |
| assert_success | |
| assert_line --index 0 "lets version ${TEST_VERSION} (${TEST_BUILD_DATE})" | |
| rm -f "${BATS_TMPDIR}/lets-version-test" |
20743cb to
d6cae4f
Compare
Summary by Sourcery
Add build date metadata to the lets binary and include it in the version output when provided.
New Features:
Enhancements:
Build:
Tests: