feat: add CLI version display with -V option (#1780)#1781
Closed
WangYihang wants to merge 1 commit into
Closed
Conversation
- 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
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 |
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 annotationsApologies for the noise. I am closing this pull request and issue now. |
Collaborator
|
No problem - glad you took it lightly. One of the best written issue/PR I've seen for a while. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
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: