Skip to content

feat: add CLI version display with -V option (#1780)#1781

Closed
WangYihang wants to merge 1 commit into
zircote:masterfrom
WangYihang:feature/cli-version-support
Closed

feat: add CLI version display with -V option (#1780)#1781
WangYihang wants to merge 1 commit into
zircote:masterfrom
WangYihang:feature/cli-version-support

Conversation

@WangYihang

@WangYihang WangYihang commented Jul 29, 2025

Copy link
Copy Markdown

Description

  • Add new Version class with Git-based semantic versioning support
  • Implement -V/--show-version CLI option to display current version
  • Support dev and dirty version suffixes for non-release builds
  • Add comprehensive unit tests for version resolution logic
  • Include composer/semver dependency for semantic version handling

Example

➜  swagger-php git:(feature/cli-version-support) git tag 5.1.5                                 
➜  swagger-php git:(feature/cli-version-support) ./bin/openapi  -V
{"version":"5.1.5","commit":"411315f3"}

Details

The version output format is JSON:

  • {"version": "X.Y.Z", "commit": "abcd1234"}
  • {"version": "X.Y.Z-dev", "commit": "efgh5678"}
  • {"version": "X.Y.Z-dev-dirty", "commit": "ijkl9012"}

Version resolution follows these rules:

  • Uses latest Git tag if current commit is tagged
  • Appends -dev suffix for untagged commits (with patch increment)
  • Appends -dirty suffix for uncommitted changes
  • Falls back to 0.0.1-dev when no tags exist

- Add new Version class with Git-based semantic versioning support
- Implement -V/--show-version CLI option to display current version
- Support dev and dirty version suffixes for non-release builds
- Add comprehensive unit tests for version resolution logic
- Include composer/semver dependency for semantic version handling

The version output format is JSON: {"version": "X.Y.Z-dev", "commit": "abcd1234"}
Version resolution follows these rules:
- Uses latest Git tag if current commit is tagged
- Appends -dev suffix for untagged commits (with patch increment)
- Appends -dirty suffix for uncommitted changes
- Falls back to 0.0.1-dev when no tags exist
@DerManoMann

Copy link
Copy Markdown
Collaborator

Hmm, admittedly I didn't think too much about how this would work, but adding two new dependencies feels definitely likey overkill to me.

Makes me wonder - is composer show so much worse?

@WangYihang

Copy link
Copy Markdown
Author

Ah, my mistake. I should have first checked if a Composer command could handle this. Running composer global show provided the packages I needed to see:

$ composer global show
Changed current directory to /tmp
nikic/php-parser              5.6.0  A PHP parser written in PHP
psr/log                       3.0.2  Common interface for logging libraries
symfony/deprecation-contracts 3.6.0  A generic function and convention to trigger deprecation notices
symfony/finder                7.3.0  Finds files and directories via an intuitive fluent interface
symfony/polyfill-ctype        1.32.0 Symfony polyfill for ctype functions
symfony/yaml                  7.3.1  Loads and dumps YAML files
zircote/swagger-php           5.1.4  Generate interactive documentation for your RESTful API using PHP attributes (preferred) or PHPDoc annotations

Apologies for the noise. I am closing this pull request and issue now.

@WangYihang WangYihang closed this Jul 30, 2025
@DerManoMann

Copy link
Copy Markdown
Collaborator

No problem - glad you took it lightly. One of the best written issue/PR I've seen for a while.
Thanks for your initiative.

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