Skip to content

Conversation

@tobert
Copy link
Owner

@tobert tobert commented Nov 9, 2025

Summary

Adds support for --version flag (and -v short form) to otel-cli, following standard CLI conventions.

Changes

  • ✅ Set rootCmd.Version in createRootCmd() to enable Cobra's built-in version flag
  • ✅ Added functional tests for both version subcommand and --version flag
  • ✅ Tests verify output format and exit code 0
  • ✅ All tests pass

Testing

Functional tests added:

  1. version subcommand - tests otel-cli version works correctly
  2. --version flag - tests otel-cli --version works correctly

Both test that:

  • Output contains version information
  • Exit code is 0

Manual testing:

$ ./otel-cli --version
otel-cli version 0.6.0-test test123 2025-11-09

$ ./otel-cli -v
otel-cli version 0.6.0-test test123 2025-11-09

$ ./otel-cli version
0.6.0-test test123 2025-11-09

Related

Fixes #9

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Why: Users expect --version flag as standard CLI pattern (issue #9)
Approach: Set rootCmd.Version in createRootCmd, add functional tests
Learned: Cobra auto-adds -v/--version when Version field is set
Next: Create PR and close issue

Changes:
- Added rootCmd.Version = config.Version in createRootCmd()
- Added functional tests for both 'version' subcommand and '--version' flag
- Tests verify output format and exit code
- All tests pass

Fixes #9

🤖 Claude <claude@anthropic.com>
Copilot AI review requested due to automatic review settings November 9, 2025 20:28
Copy link
Contributor

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 support for the standard --version flag (and -v short form) to otel-cli, complementing the existing version subcommand by setting Cobra's built-in version support.

Key changes:

  • Enables Cobra's built-in --version flag by setting rootCmd.Version
  • Adds functional tests for both the version subcommand and --version flag

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
otelcli/root.go Sets rootCmd.Version to enable Cobra's built-in version flag support
data_for_test.go Adds test cases for both version subcommand and --version flag functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Why: Need to validate version output format supports both 'unknown' and version strings
Approach: Use CheckFuncs to validate output format while stripping variable content
Learned: CheckFunc provides better validation than regex for variable content
Next: Push and verify CI passes

Changes:
- Added strings import to data_for_test.go
- Added CheckFunc for version subcommand to validate format
- Added CheckFunc for --version flag to validate 'otel-cli version X' format
- Both CheckFuncs handle 'unknown' or multi-part version strings
- Use regex  to strip content for checkOutput comparison

🤖 Claude <claude@anthropic.com>
@tobert
Copy link
Owner Author

tobert commented Nov 9, 2025

Test Update

Added proper version output validation using CheckFuncs:

Why CheckFuncs?

  • Version output varies ("unknown" vs "version commit date")
  • CheckFuncs validate format while allowing variable content
  • More robust than simple regex matching

What's validated:

  • version subcommand: outputs version string (handles "unknown" or multi-part)
  • --version flag: outputs "otel-cli version X" format
  • Both: exit code 0

How it works:

  • Regex .+ strips variable content for checkOutput comparison
  • CheckFuncs validate actual output format
  • Supports both "unknown" (no ldflags) and "0.6.0 abc123 2025-11-09" (with ldflags)

CI passing ✅

🤖 Claude claude@anthropic.com

@tobert tobert merged commit fc73ce7 into main Nov 10, 2025
1 check passed
@tobert tobert deleted the add-version-flag branch November 10, 2025 02:10
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.

Add command to print version

2 participants