calver

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 8 Imported by: 0

README

calver CI Go Reference Coverage Code to Test Ratio

calver is a package/tool provides the ability to work with Calendar Versioning in Go.

Usage

As a package
package main

import (
	"fmt"

	"github.com/k1LoW/calver"
)

func main() {
	cv, _ := calver.Parse("YY.0M.MICRO", "23.05.1")
	fmt.Println(cv) // Output: 23.05.1
	ncv, _ := cv.Next()
	fmt.Println(ncv) // Output: 23.05.2
}
As a tool
$ date
Tue May  9 13:04:09 UTC 2023
$ calver --layout YY.0M.MICRO
23.5.0
$ calver --layout YY.0M.MICRO | calver --layout YY.0M.MICRO --next
23.5.1
Example: Generate version like Ubuntu
$ date
Tue May  9 13:04:09 UTC 2023
$ calver --layout YY.0M.MICRO --trim-suffix
2023.05
$ calver --layout YY.0M.MICRO --trim-suffix | calver --layout YY.0M.MICRO --trim-suffix --next
2023.05.1
Example: Use modifier
$ date
Tue May  9 13:04:09 UTC 2023
$ calver --layout YY.0M.MICRO-MODIFIER --trim-suffix --modifier dev
2023.05-dev
$ calver 23.05-dev --layout YY.0M.MICRO-MODIFIER --trim-suffix --next
2023.05
$ calver 23.05 --layout YY.0M.MICRO-MODIFIER --trim-suffix --next
2023.05.1
Example: Get latest version and generate next version
$ date
Tue May  9 13:04:09 UTC 2023
$ gh release list | cut -f 1
v1.1.2
v1.1.1
2023.05.1
2023.05.0
v1.1.0
v1.0.1
2023.03.1
2023.03.0
v1.0.0
2023.02.0
v0.1.0
$ gh release list | cut -f 1 | calver --layout YY.0M.MICRO
2023.05.1
$ gh release list | cut -f 1 | calver --layout YY.0M.MICRO --next
2023.05.2

Install

As a package
$ go get github.com/k1LoW/calver
As a tool

deb:

$ export CALVER_VERSION=X.X.X
$ curl -o calver.deb -L https://github.com/k1LoW/calver/releases/download/v$CALVER_VERSION/calver_$CALVER_VERSION-1_amd64.deb
$ dpkg -i calver.deb

RPM:

$ export CALVER_VERSION=X.X.X
$ yum install https://github.com/k1LoW/calver/releases/download/v$CALVER_VERSION/calver_$CALVER_VERSION-1_amd64.rpm

apk:

$ export CALVER_VERSION=X.X.X
$ curl -o calver.apk -L https://github.com/k1LoW/calver/releases/download/v$CALVER_VERSION/calver_$CALVER_VERSION-1_amd64.apk
$ apk add calver.apk

homebrew tap:

$ brew install k1LoW/tap/calver

manually:

Download binary from releases page

go install:

$ go install github.com/k1LoW/calver/cmd/calver@latest

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoVersions = errors.New("no versions")

Functions

func IsTimeVersionFirst added in v0.7.2

func IsTimeVersionFirst(layout []token) bool

IsTimeVersionFirst returns true if the time version is first in the layout.

Types

type Calver

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

func New

func New(layout string) (*Calver, error)

New returns *Calver at the current time.

func NewWithTime

func NewWithTime(layout string, now time.Time) (*Calver, error)

NewWithTime returns *Calver at the given time.

func Parse

func Parse(layout, value string) (*Calver, error)

Parse version string using layout at the current time.

func (*Calver) In

func (cv *Calver) In(loc *time.Location) *Calver

In sets *time.Location.

func (*Calver) Layout

func (cv *Calver) Layout() string

Layout returns version layout.

func (*Calver) Major

func (cv *Calver) Major() (*Calver, error)

Major returns next major version *Calver.

func (*Calver) Micro

func (cv *Calver) Micro() (*Calver, error)

Micro returns next micro version *Calver.

func (*Calver) Minor

func (cv *Calver) Minor() (*Calver, error)

Minor returns next minor version *Calver.

func (*Calver) Modifier

func (cv *Calver) Modifier(m string) (*Calver, error)

Modifier returns *Calver with modifier.

func (*Calver) Next

func (cv *Calver) Next() (*Calver, error)

Next returns next version *Calver at the current time.

func (*Calver) NextWithTime

func (cv *Calver) NextWithTime(now time.Time) (ncv *Calver, err error)

Next returns next version *Calver at the given time.

func (*Calver) Parse

func (cv *Calver) Parse(value string) (ncv *Calver, err error)

Parse version string using layout.

func (*Calver) String

func (cv *Calver) String() string

String returns version string.

func (*Calver) TrimSuffix added in v0.6.0

func (cv *Calver) TrimSuffix(enable bool) *Calver

TrimSuffix returns *Calver enabled/diabled to trim the trailing version of a zero value or an empty string.

type Calvers added in v0.5.0

type Calvers []*Calver

func (Calvers) Latest added in v0.5.0

func (cvs Calvers) Latest() (*Calver, error)

func (Calvers) Sort added in v0.5.0

func (cvs Calvers) Sort()

Directories

Path Synopsis
cmd
calver command

Jump to

Keyboard shortcuts

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