gosemver

package module
Version: v0.0.0-...-9f9d47a Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2014 License: Apache-2.0 Imports: 4 Imported by: 0

README

gosemver Build Status Coverage Status Apache License 2.0

A Semantic Versioning library for the Go programming language.

Usage

import "github.com/myfreeweb/gosemver"

Parsing:

gosemver.ParseVersion("v0.1.0-alpha+build001") // gosemver.Version{"v", 0, 1, 0, "alpha", "build001"}, nil
gosemver.ParseVersion("AAAAAAA") // gosemver.Version{"", 0, 0, 0, "", ""}, error

gosemver.ParseVersions([]string{"0.1.0", "0.2.0"}) // []gosemver.Version{{"", 0, 1, 0, "", ""}, {"", 0, 2, 0, "", ""},}, nil

Sorting:

import "sort"

vers := []gosemver.Version{
  gosemver.Version{"v", 1, 0, 0, "", ""},
  gosemver.Version{"v", 0, 1, 0, "", ""},
}

sort.Sort(gosemver.Versions(vers))

Output:

ver := gosemver.Version{"v", 2, 3, 1, "alpha", "build.001"}
ver.String() // "v2.3.1-alpha+build.001"

Constraints:

ver := gosemver.Version{"", 3, 0, 3, "", ""}
// returns result, error:
ver.Satisfies("*") // true, nil
ver.Satisfies("== 3.0.3") // true, nil
ver.Satisfies(">= 3.0.1") // true, nil
ver.Satisfies(">= 3.0") // true, nil
ver.Satisfies("> 3.0.0") // true, nil
ver.Satisfies("~> 3.0.4") // false, nil
ver.Satisfies("~> 3.0.1") // true, nil
ver.Satisfies("~> 3.0") // true, nil
ver.Satisfies("~> 2.9") // false, nil
ver.Satisfies("^2.9") // false, nil
// ^ and ~> are the same operator
vers := []gosemver.Version{
  gosemver.Version{"", 1, 2, 3, "", ""},
  gosemver.Version{"", 0, 1, 5, "", ""},
  gosemver.Version{"", 1, 0, 0, "", ""},
}

gosemver.FindAll(vers, ">= 1.0.0") // []gosemver.Version{gosemver.Version{"", 1, 2, 3, "", ""}, gosemver.Version{"", 1, 0, 0, "", ""},}
gosemver.FindMax(vers, ">= 1.0.0") // gosemver.Version{"", 1, 2, 3, "", ""}, nil
gosemver.FindMax(vers, ">= 999.0.0") // gosemver.Version{"", 0, 0, 0, "", ""}, error

TODO

  • more constraints (like node semver)
  • executable (like, ls | gosemver sort, gosemver inc patch 1.1.0)

License

Copyright 2014 Greg V floatboth@me.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constraint

type Constraint struct {
	Major      int
	Minor      int
	Patch      int
	MatchPatch bool // because Go does not have neither uninitialized variables nor Option/Maybe, how the fuck else do we know if Patch == 0 means match against zero or don't match?
}

func MustParseConstraint

func MustParseConstraint(input string) (string, Constraint)

func ParseConstraint

func ParseConstraint(input string) (string, Constraint, error)

type Version

type Version struct {
	Prefix        string // Technically not a part of semver
	Major         int
	Minor         int
	Patch         int
	Identifiers   string
	BuildMetadata string
}

func FindAll

func FindAll(vers []Version, constraint string) ([]Version, error)

func FindAllOp

func FindAllOp(vers []Version, operator string, constraint Constraint) []Version

func FindMax

func FindMax(vers []Version, constraint string) (Version, error)

func FindMaxOp

func FindMaxOp(vers []Version, operator string, constraint Constraint) (Version, error)

func MustFindAll

func MustFindAll(vers []Version, constraint string) []Version

func MustFindMax

func MustFindMax(vers []Version, constraint string) Version

func MustParseVersion

func MustParseVersion(input string) Version

func MustParseVersions

func MustParseVersions(input []string) []Version

func ParseVersion

func ParseVersion(input string) (Version, error)

func ParseVersions

func ParseVersions(input []string) ([]Version, error)

func (Version) Satisfies

func (v Version) Satisfies(constraint string) (result bool, err error)

func (Version) SatisfiesExact

func (v Version) SatisfiesExact(c Constraint) bool

func (Version) SatisfiesGreaterThan

func (v Version) SatisfiesGreaterThan(c Constraint) bool

func (Version) SatisfiesGreaterThanOrEqual

func (v Version) SatisfiesGreaterThanOrEqual(c Constraint) bool

func (Version) SatisfiesLessThan

func (v Version) SatisfiesLessThan(c Constraint) bool

func (Version) SatisfiesLessThanOrEqual

func (v Version) SatisfiesLessThanOrEqual(c Constraint) bool

func (Version) SatisfiesOp

func (v Version) SatisfiesOp(operator string, constr Constraint) bool

func (Version) SatisfiesPessimistic

func (v Version) SatisfiesPessimistic(c Constraint) bool

func (Version) String

func (v Version) String() string

implementing fmt.Stringer

type Versions

type Versions []Version

func (Versions) Len

func (v Versions) Len() int

func (Versions) Less

func (v Versions) Less(i, j int) bool

func (Versions) Swap

func (v Versions) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL