From 8b3c34c308ccf2bc20c095637a2049f8f7f04a23 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 15 Apr 2018 11:11:07 -0300 Subject: [PATCH] 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. --- internal/taskfile/taskfile.go | 3 +++ internal/taskfile/version/version.go | 37 ++++++++++++---------------- task.go | 11 ++++++--- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/internal/taskfile/taskfile.go b/internal/taskfile/taskfile.go index b874c610..2ac0cf50 100644 --- a/internal/taskfile/taskfile.go +++ b/internal/taskfile/taskfile.go @@ -4,6 +4,7 @@ package taskfile type Taskfile struct { Version string Expansions int + Output string Vars Vars Tasks Tasks } @@ -18,6 +19,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error { var taskfile struct { Version string Expansions int + Output string Vars Vars Tasks Tasks } @@ -26,6 +28,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error { } tf.Version = taskfile.Version tf.Expansions = taskfile.Expansions + tf.Output = taskfile.Output tf.Vars = taskfile.Vars tf.Tasks = taskfile.Tasks if tf.Expansions <= 0 { diff --git a/internal/taskfile/version/version.go b/internal/taskfile/version/version.go index b0a6563b..2853c5c3 100644 --- a/internal/taskfile/version/version.go +++ b/internal/taskfile/version/version.go @@ -5,27 +5,30 @@ import ( ) var ( - v1 = mustVersion("1") - v2 = mustVersion("2") - - isV1 = mustConstraint("= 1") - isV2 = mustConstraint(">= 2") - isV21 = mustConstraint(">= 2.1") + v1 = mustVersion("1") + v2 = mustVersion("2") + v21 = mustVersion("2.1") + v22 = mustVersion("2.2") ) // IsV1 returns if is a given Taskfile version is version 1 -func IsV1(v *semver.Version) bool { - return isV1.Check(v) +func IsV1(v *semver.Constraints) bool { + return v.Check(v1) } // IsV2 returns if is a given Taskfile version is at least version 2 -func IsV2(v *semver.Version) bool { - return isV2.Check(v) +func IsV2(v *semver.Constraints) bool { + return v.Check(v2) } -// IsV21 returns if is a given Taskfile version is at least version 2 -func IsV21(v *semver.Version) bool { - return isV21.Check(v) +// IsV21 returns if is a given Taskfile version is at least version 2.1 +func IsV21(v *semver.Constraints) bool { + 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 { @@ -35,11 +38,3 @@ func mustVersion(s string) *semver.Version { } return v } - -func mustConstraint(s string) *semver.Constraints { - c, err := semver.NewConstraint(s) - if err != nil { - panic(err) - } - return c -} diff --git a/task.go b/task.go index cade5d35..60f7bb39 100644 --- a/task.go +++ b/task.go @@ -79,7 +79,7 @@ func (e *Executor) Setup() error { return err } - v, err := semver.NewVersion(e.Taskfile.Version) + v, err := semver.NewConstraint(e.Taskfile.Version) if err != nil { 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, Logger: e.Logger, } - case version.IsV2(v): + case version.IsV2(v), version.IsV21(v): e.Compiler = &compilerv2.CompilerV2{ Dir: e.Dir, Taskvars: e.taskvars, @@ -116,8 +116,11 @@ func (e *Executor) Setup() error { Expansions: e.Taskfile.Expansions, Logger: e.Logger, } - case version.IsV21(v): - return fmt.Errorf(`task: Taskfile versions greater than v2 not implemented in the version of Task`) + case version.IsV22(v): + 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))