semver

package module
v0.0.0-...-84a46a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2018 License: MIT Imports: 7 Imported by: 0

README

Semver

Semver is a Go implementation of Composer's Semver parser.

Usage

To use Semver, add it to your project

$ go get github.com/tempo-cli/semver

Then you can import the package in your project:

import "gitub.com/tempo-cli/semver"

For more information on suported versions and constraints, visit the Composer documentation

Parsing versions

To parse a version, use the NewVersion function which will return a Version instance


version := semver.NewVersion("v1.2.3")

fmt.PrintLn(version.Major) // Prints '1'
fmt.PrintLn(version.Minor) // Prints '2'
fmt.PrintLn(version.Patch) // Prints '3'

You can parse various different version constraints, including branch names and normalizing values.

Parsing constraints

To parse a version constraint, use the NewConstraint function which will return a Constraint struct which contains the lower and upper bound for the constraint


constraint := semver.NewConstraint("^2.0")

fmt.PrintLn(constraint.constraints[0].String) // Prints '>= 2.0.0.0-dev'
fmt.PrintLn(constraint.constraints[1].String) // Prints '< 3.0.0.0-dev'

TODO

  • Update documentation with more use cases
  • Compare versions

Contributing

If you would like to contribute to this project, create a fork and send a pull request with your changes. Alternatively you can open an issue if something is not working as expectec

Documentation

Index

Constants

View Source
const (
	LessThan = iota - 1
	Equal
	GreaterThan
)

Variables

This section is empty.

Functions

func ParseStability

func ParseStability(stability string) string

Types

type Constraint

type Constraint struct {
	// contains filtered or unexported fields
}

func NewConstraint

func NewConstraint(constraint string) (*Constraint, error)

func (*Constraint) Matches

func (c *Constraint) Matches(version *Version) bool

func (*Constraint) String

func (c *Constraint) String() string

type Version

type Version struct {
	Major, Minor, Patch, Extra int
	PreRelease                 string
	State                      string
	Stability                  string
	Metadata                   string
	Original                   string
	Parsed                     string
	// contains filtered or unexported fields
}

func NewVersion

func NewVersion(version string) (*Version, error)

func NormalizeBranch

func NormalizeBranch(branch string) (*Version, error)

func (*Version) Compare

func (a *Version) Compare(b *Version, operator string) bool

func (*Version) Equal

func (a *Version) Equal(b *Version) bool

func (*Version) GreaterThan

func (a *Version) GreaterThan(b *Version) bool

func (*Version) GreaterThanOrEqual

func (a *Version) GreaterThanOrEqual(b *Version) bool

func (*Version) LessThan

func (a *Version) LessThan(b *Version) bool

func (*Version) LessThanOrEqual

func (a *Version) LessThanOrEqual(b *Version) bool

func (*Version) NotEqual

func (a *Version) NotEqual(b *Version) bool

func (*Version) String

func (v *Version) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL