mirror of
https://github.com/go-task/task.git
synced 2025-07-15 01:35:00 +02:00
Use semver for Taskfile versions
This commit is contained in:
@ -2,8 +2,7 @@ package taskfile
|
||||
|
||||
// Taskfile represents a Taskfile.yml
|
||||
type Taskfile struct {
|
||||
// TODO: version is still not used
|
||||
Version int
|
||||
Version string
|
||||
Tasks Tasks
|
||||
}
|
||||
|
||||
@ -14,7 +13,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
}
|
||||
|
||||
var taskfile struct {
|
||||
Version int
|
||||
Version string
|
||||
Tasks Tasks
|
||||
}
|
||||
if err := unmarshal(&taskfile); err != nil {
|
||||
|
45
internal/taskfile/version/version.go
Normal file
45
internal/taskfile/version/version.go
Normal file
@ -0,0 +1,45 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"github.com/Masterminds/semver"
|
||||
)
|
||||
|
||||
var (
|
||||
v1 = mustVersion("1")
|
||||
v2 = mustVersion("2")
|
||||
|
||||
isV1 = mustConstraint("= 1")
|
||||
isV2 = mustConstraint(">= 2")
|
||||
isV21 = mustConstraint(">= 2.1")
|
||||
)
|
||||
|
||||
// IsV1 returns if is a given Taskfile version is version 1
|
||||
func IsV1(v *semver.Version) bool {
|
||||
return isV1.Check(v)
|
||||
}
|
||||
|
||||
// IsV2 returns if is a given Taskfile version is at least version 2
|
||||
func IsV2(v *semver.Version) bool {
|
||||
return isV2.Check(v)
|
||||
}
|
||||
|
||||
// IsV21 returns if is a given Taskfile version is at least version 2
|
||||
func IsV21(v *semver.Version) bool {
|
||||
return isV21.Check(v)
|
||||
}
|
||||
|
||||
func mustVersion(s string) *semver.Version {
|
||||
v, err := semver.NewVersion(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func mustConstraint(s string) *semver.Constraints {
|
||||
c, err := semver.NewConstraint(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return c
|
||||
}
|
Reference in New Issue
Block a user