Add version command and improve flag descriptions#41
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a version subcommand and improves flag descriptions for better user experience. The implementation includes smart version detection using git tags/commits and comprehensive test coverage.
- Add
versionsubcommand that shows identical output to--versionflag - Enhance Makefile to inject git-based version info during builds
- Improve flag descriptions to be more user-friendly
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/version.bats | Adds comprehensive test coverage for version functionality |
| cmd/version.go | Implements new version subcommand with consistent output |
| cmd/root.go | Overrides default help and version flag descriptions |
| Makefile | Adds git-based version injection via LDFLAGS |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
justincampbell
left a comment
There was a problem hiding this comment.
✅ Addressed: Removed flag redefinition approach and implemented custom flag descriptions using SetHelpFunc() instead. This avoids conflicts with Cobra's built-in flags while achieving the desired custom descriptions.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
cmd/root.go
Outdated
| // Customize flag descriptions using a custom help function | ||
| originalHelpFunc := RootCmd.HelpFunc() | ||
| RootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { | ||
| // Modify flag descriptions before showing help | ||
| if helpFlag := cmd.Flags().Lookup("help"); helpFlag != nil { | ||
| helpFlag.Usage = "Show help" | ||
| } | ||
| if versionFlag := cmd.Flags().Lookup("version"); versionFlag != nil { | ||
| versionFlag.Usage = "Show version info" | ||
| } | ||
| originalHelpFunc(cmd, args) | ||
| }) |
There was a problem hiding this comment.
This approach modifies global state in the Execute function and creates a closure that captures the original help function. Consider setting these flag descriptions during command initialization instead of dynamically modifying them each time help is displayed.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
cmd/root.go
Outdated
| // Store original help function and customize flag descriptions with sync.Once for efficiency | ||
| originalHelpFunc := RootCmd.HelpFunc() | ||
| RootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { | ||
| customizeOnce.Do(func() { | ||
| // Customize built-in flag descriptions once | ||
| if helpFlag := cmd.Flags().Lookup("help"); helpFlag != nil { | ||
| helpFlag.Usage = "Show help" | ||
| } | ||
| if versionFlag := cmd.Flags().Lookup("version"); versionFlag != nil { | ||
| versionFlag.Usage = "Show version info" | ||
| } | ||
| }) | ||
| // Use original help function | ||
| originalHelpFunc(cmd, args) | ||
| }) |
There was a problem hiding this comment.
The help function customization runs on every help invocation. Consider moving the flag customization to the init() function or Execute() function start to avoid the overhead of function wrapping and sync.Once checks on each help call.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
cmd/version.go
Outdated
| var versionCmd = &cobra.Command{ | ||
| Use: "version", | ||
| Short: "Print version information", | ||
| Long: "Print version information", |
There was a problem hiding this comment.
[nitpick] The Long description is identical to the Short description. Consider providing a more detailed explanation in the Long field or removing it to use the default behavior.
| Long: "Print version information", |
6dda2fc to
2604fdb
Compare
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Add 'version' subcommand that shows same output as --version flag - Enhance Makefile to inject git-based version info during local builds - Use git tags when available, fall back to commit hash (no commit counts or build dates) - Add comprehensive test coverage for version functionality - Compatible with both local builds and GoReleaser releases Implementation notes: - Directly use RootCmd.Version for simplicity (no wrapper functions) - Clean command definition without redundant descriptions - Addresses all Copilot feedback for proper Cobra usage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2604fdb to
dd6c512
Compare
Summary
versionsubcommand that shows identical output to--versionflagChanges Made
Version Implementation
versionsubcommand: Shows same output as--versionflag for consistencyv1.0.0), falls back to commit hash (e.g.,2eeb771)Improved Flag Descriptions
--helpnow shows "Show help" instead of "help for pomodoro"--versionnow shows "Show version info" instead of "version for pomodoro"Testing
test/version.bats--versionflag andversionsubcommandUsage Examples
Technical Details
-X main.Version=$(VERSION)git describe --tags --exact-matchfor tagged releasesgit rev-parse --short HEADfor development builds🤖 Generated with Claude Code