1
0
mirror of https://github.com/go-task/task.git synced 2025-06-17 00:17:51 +02:00

Add "output" options to the Taskfile

Also, fix handling of Taskfile by making the version an instance of
`semver.Constraints` instead of `semver.Version`. This makes the version
works as described on TASKFILE_VERSIONS.md document, i.e. version "2" will
include "2.x" features but version "2.0" not.
This commit is contained in:
Andrey Nering
2018-04-15 11:11:07 -03:00
parent 2cb2668803
commit 8b3c34c308
3 changed files with 26 additions and 25 deletions

View File

@ -4,6 +4,7 @@ package taskfile
type Taskfile struct { type Taskfile struct {
Version string Version string
Expansions int Expansions int
Output string
Vars Vars Vars Vars
Tasks Tasks Tasks Tasks
} }
@ -18,6 +19,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error {
var taskfile struct { var taskfile struct {
Version string Version string
Expansions int Expansions int
Output string
Vars Vars Vars Vars
Tasks Tasks Tasks Tasks
} }
@ -26,6 +28,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error {
} }
tf.Version = taskfile.Version tf.Version = taskfile.Version
tf.Expansions = taskfile.Expansions tf.Expansions = taskfile.Expansions
tf.Output = taskfile.Output
tf.Vars = taskfile.Vars tf.Vars = taskfile.Vars
tf.Tasks = taskfile.Tasks tf.Tasks = taskfile.Tasks
if tf.Expansions <= 0 { if tf.Expansions <= 0 {

View File

@ -5,27 +5,30 @@ import (
) )
var ( var (
v1 = mustVersion("1") v1 = mustVersion("1")
v2 = mustVersion("2") v2 = mustVersion("2")
v21 = mustVersion("2.1")
isV1 = mustConstraint("= 1") v22 = mustVersion("2.2")
isV2 = mustConstraint(">= 2")
isV21 = mustConstraint(">= 2.1")
) )
// IsV1 returns if is a given Taskfile version is version 1 // IsV1 returns if is a given Taskfile version is version 1
func IsV1(v *semver.Version) bool { func IsV1(v *semver.Constraints) bool {
return isV1.Check(v) return v.Check(v1)
} }
// IsV2 returns if is a given Taskfile version is at least version 2 // IsV2 returns if is a given Taskfile version is at least version 2
func IsV2(v *semver.Version) bool { func IsV2(v *semver.Constraints) bool {
return isV2.Check(v) return v.Check(v2)
} }
// IsV21 returns if is a given Taskfile version is at least version 2 // IsV21 returns if is a given Taskfile version is at least version 2.1
func IsV21(v *semver.Version) bool { func IsV21(v *semver.Constraints) bool {
return isV21.Check(v) return v.Check(v21)
}
// IsV22 returns if is a given Taskfile version is at least version 2.2
func IsV22(v *semver.Constraints) bool {
return v.Check(v22)
} }
func mustVersion(s string) *semver.Version { func mustVersion(s string) *semver.Version {
@ -35,11 +38,3 @@ func mustVersion(s string) *semver.Version {
} }
return v return v
} }
func mustConstraint(s string) *semver.Constraints {
c, err := semver.NewConstraint(s)
if err != nil {
panic(err)
}
return c
}

11
task.go
View File

@ -79,7 +79,7 @@ func (e *Executor) Setup() error {
return err return err
} }
v, err := semver.NewVersion(e.Taskfile.Version) v, err := semver.NewConstraint(e.Taskfile.Version)
if err != nil { if err != nil {
return fmt.Errorf(`task: could not parse taskfile version "%s": %v`, e.Taskfile.Version, err) return fmt.Errorf(`task: could not parse taskfile version "%s": %v`, e.Taskfile.Version, err)
} }
@ -108,7 +108,7 @@ func (e *Executor) Setup() error {
Vars: e.taskvars, Vars: e.taskvars,
Logger: e.Logger, Logger: e.Logger,
} }
case version.IsV2(v): case version.IsV2(v), version.IsV21(v):
e.Compiler = &compilerv2.CompilerV2{ e.Compiler = &compilerv2.CompilerV2{
Dir: e.Dir, Dir: e.Dir,
Taskvars: e.taskvars, Taskvars: e.taskvars,
@ -116,8 +116,11 @@ func (e *Executor) Setup() error {
Expansions: e.Taskfile.Expansions, Expansions: e.Taskfile.Expansions,
Logger: e.Logger, Logger: e.Logger,
} }
case version.IsV21(v): case version.IsV22(v):
return fmt.Errorf(`task: Taskfile versions greater than v2 not implemented in the version of Task`) return fmt.Errorf(`task: Taskfile versions greater than v2.1 not implemented in the version of Task`)
}
if !version.IsV21(v) && e.Taskfile.Output != "" {
return fmt.Errorf(`task: Taskfile option "output" is only available starting on Taskfile version v2.1`)
} }
e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks)) e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks))