Skip to content

add Core func - #85

Merged
kmoe merged 1 commit into
masterfrom
base-version-func
Mar 31, 2021
Merged

kmoe merged 1 commit into
masterfrom
base-version-func

Conversation

@kmoe

@kmoe kmoe commented Mar 30, 2021 •

Copy link
Copy Markdown
Member

Adds a Core function to Version, which returns a new Version created from only the MAJOR.MINOR.PATCH segments of the original version, without prerelease or metadata strings.

Consumers of go-version often want to treat prereleases of versions as equal to non-prerelease versions, e.g. 0.15.0-dev as equal to 0.15.0. The present functionality is intended as an easy way to opt in to this behaviour.

Example in a library used by the Terraform Language Server:
https://github.com/hashicorp/terraform-schema/blob/8c206fbd85ae346716b4efbd776c8b8097fc5b42/schema/core_schema.go#L47-L52

@kmoe

kmoe commented Mar 30, 2021

Copy link
Copy Markdown
Member Author

Perhaps we could call this function SegmentsOnly, or some variation of this, since go-version uses the "segments" terminology to refer to the MAJOR.MINOR.PATCH numeric segments only.

@radeksimko radeksimko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, I suppose this doesn't need too wide attention/approval given that the change is additive and shouldn't break existing usage, but it would be useful to have an additional 👍🏻 from TF core.

@alisdair alisdair left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This makes sense to me, and I think we'd probably use it to address hashicorp/terraform#28148 while still preserving the existing behaviour of ignoring prerelease versions when evaluating version constraint inequalities.

Adds a Core function to Version, which returns a new Version created from only
the MAJOR.MINOR.PATCH segments of the original version, without prerelease or
metadata strings.

Consumers of go-version often want to treat prereleases of versions as equal to
non-prerelease versions, e.g. 0.15.0-dev as equal to 0.15.0. The present
functionality is intended as an easy way to opt in to this behaviour.
@kmoe
kmoe force-pushed the base-version-func branch from cb20135 to 7da126b Compare March 31, 2021 15:04
@kmoe

kmoe commented Mar 31, 2021

Copy link
Copy Markdown
Member Author

The semver spec actually calls this core in the grammar (https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions), so I've renamed it. Would appreciate a go-ahead from both of you on this.

@kmoe kmoe changed the title add Base func add Core func Mar 31, 2021
@kmoe
kmoe requested review from alisdair and radeksimko March 31, 2021 15:05
@kmoe
kmoe merged commit 3307340 into master Mar 31, 2021
@kmoe
kmoe deleted the base-version-func branch March 31, 2021 15:12
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.

3 participants