feat: add --json flag - #261
Merged
Merged
Conversation
caarlos0
reviewed
Oct 23, 2025
Comment on lines
+254
to
+265
| m := make(map[string]any) | ||
| m["prefix"] = opts.Prefix | ||
| m["version"] = opts.Prefix + v.String() | ||
| m["major"] = v.Major() | ||
| m["minor"] = v.Minor() | ||
| m["patch"] = v.Patch() | ||
| m["metadata"] = v.Metadata() | ||
| m["prerelease"] = v.Prerelease() | ||
| if release := strings.SplitN(v.Prerelease(), ".", 2); len(release) == 2 { | ||
| m["prerelease"] = release[0] | ||
| m["build"] = release[1] | ||
| } |
Owner
There was a problem hiding this comment.
i think it is probably clearer to have a type here instead of a map
also adds the benefit that people that want to parse it can just copy the struct from here.
The `--json` flag allows to output version as json.
Author
|
does this works? type VersionInfo struct {
Version string `json:"version"`
Major uint64 `json:"major"`
Minor uint64 `json:"minor"`
Patch uint64 `json:"patch"`
Prefix string `json:"prefix,omitempty"`
Metadata string `json:"metadata,omitempty"`
Prerelease string `json:"prerelease,omitempty"`
Build string `json:"build,omitempty"`
} |
Owner
|
that looks great, thank you! |
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.
The
--jsonflag allows to output version as json.{ "major": 3, "minor": 2, "patch": 4, "metadata": "", "prefix": "v", "prerelease": "", "version": "v3.2.4" }Why?
It gives more control of over version. My reason for adding this flag is adding prerelease automatically using shell script. Something like this:
It can be done with grep but it much nicer and reliable. Thanks!