Skip to content

Add version command and improve flag descriptions#41

Merged
justincampbell merged 1 commit intomainfrom
add-version-command
Sep 25, 2025
Merged

Add version command and improve flag descriptions#41
justincampbell merged 1 commit intomainfrom
add-version-command

Conversation

@justincampbell
Copy link
Copy Markdown
Member

Summary

  • Add version subcommand that shows identical output to --version flag
  • Enhance Makefile to inject git-based version info during local builds
  • Improve flag descriptions to be more user-friendly
  • Add comprehensive test coverage for version functionality

Changes Made

Version Implementation

  • New version subcommand: Shows same output as --version flag for consistency
  • Smart version detection: Uses git tags when available (e.g., v1.0.0), falls back to commit hash (e.g., 2eeb771)
  • Enhanced Makefile: Automatically injects version info from git during local builds
  • GoReleaser compatibility: Updated configuration to work with releases

Improved Flag Descriptions

  • --help now shows "Show help" instead of "help for pomodoro"
  • --version now shows "Show version info" instead of "version for pomodoro"
  • More concise and user-friendly descriptions

Testing

  • Added comprehensive test suite in test/version.bats
  • Tests both --version flag and version subcommand
  • Verifies help output includes version command
  • All 65 tests pass

Usage Examples

# Both commands show identical output
$ pomodoro --version
pomodoro version 2eeb771

$ pomodoro version  
pomodoro version 2eeb771

# Clean flag descriptions in help
$ pomodoro --help
...
  -h, --help               Show help
  -v, --version            Show version info
...

Technical Details

  • Version is injected via LDFLAGS during build: -X main.Version=$(VERSION)
  • Uses git describe --tags --exact-match for tagged releases
  • Falls back to git rev-parse --short HEAD for development builds
  • No build dates or commit counts (as requested)
  • Simple, clean implementation with minimal code

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings September 25, 2025 16:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 version subcommand that shows identical output to --version flag
  • 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.

Copilot AI review requested due to automatic review settings September 25, 2025 16:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

@justincampbell justincampbell left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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
Comment on lines +69 to +80
// 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)
})
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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
Comment on lines +72 to +86
// 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)
})
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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",
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

[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.

Suggested change
Long: "Print version information",

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>
@justincampbell justincampbell merged commit 714ca9b into main Sep 25, 2025
2 checks passed
@justincampbell justincampbell deleted the add-version-command branch September 25, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants