Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tangrufus committed Nov 15, 2024
1 parent dddf2b5 commit 4edea2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@

### `Version`

[`NewVersion`](https://pkg.go.dev/github.com/typisttech/comver#NewVersion) attempts to coerce a version string into a composer version and parse it.
[`NewVersion`](https://pkg.go.dev/github.com/typisttech/comver#NewVersion) parses a given version string, attempts to coerce a version string into a [`Version`](https://pkg.go.dev/github.com/typisttech/comver#Version) object or return an error if unable to parse the version string.

If there is a leading v or a version listed without all parts (e.g. `v1.2`) it will attempt to coerce it into a valid composer version (e.g. `1.2.0.0`). In both cases a [`Version`](https://pkg.go.dev/github.com/typisttech/comver#Version) object is returned that can be sorted, compared, and used in constraints.

An error is returned if there is an issue parsing the version.

> [!WARNING]
> Due to implementation complexity, it only supports a subset of [composer versioning](https://github.com/composer/semver/).
>
> Refer to the [`version_test.go`](version_test.go) for examples.

```go
ss := []string{
Expand Down Expand Up @@ -155,7 +160,7 @@ fmt.Println(is)

## Credits

[comver](https://github.com/typisttech/comver) is a [Typist Tech](https://typist.tech) project and maintained by [Tang Rufus](https://x.com/TangRufus), freelance developer for [hire](https://typist.tech/contact/).
[`comver`](https://github.com/typisttech/comver) is a [Typist Tech](https://typist.tech) project and maintained by [Tang Rufus](https://x.com/TangRufus), freelance developer for [hire](https://typist.tech/contact/).

Full list of contributors can be found [here](https://github.com/typisttech/comver/graphs/contributors).

Expand Down
10 changes: 8 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ type Version struct {
original string `exhaustruct:"optional"`
}

// NewVersion parses a given version string and returns an instance of [Version] or
// an error if unable to parse the version.
// NewVersion parses a given version string, attempts to coerce a version string into
// a [Version] object or return an error if unable to parse the version string.
//
// If there is a leading v or a version listed without all parts (e.g. v1.2) it will
// attempt to coerce it into a valid composer version (e.g. 1.2.0.0). In both cases
// a [Version] object is returned that can be sorted, compared, and used in constraints.
//
// Due to implementation complexity, it only supports a subset of [composer versioning].
// Refer to the [version_test.go] for examples.
//
// [composer versioning]: https://github.com/composer/semver/
// [version_test.go]: https://github.com/typisttech/comver/blob/main/version_test.go
func NewVersion(v string) (Version, error) { //nolint:cyclop,funlen
original := v

Expand Down

0 comments on commit 4edea2c

Please sign in to comment.