2018-02-17 18:22:18 +02:00
|
|
|
package taskfile
|
|
|
|
|
2020-05-17 20:42:27 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2018-02-17 18:22:18 +02:00
|
|
|
// Taskfile represents a Taskfile.yml
|
|
|
|
type Taskfile struct {
|
2018-03-04 20:50:03 +02:00
|
|
|
Version string
|
|
|
|
Expansions int
|
2022-02-20 00:31:27 +02:00
|
|
|
Output Output
|
2019-09-09 03:26:24 +02:00
|
|
|
Method string
|
2021-01-01 23:27:50 +02:00
|
|
|
Includes *IncludedTaskfiles
|
2020-03-29 21:54:59 +02:00
|
|
|
Vars *Vars
|
|
|
|
Env *Vars
|
2018-03-04 20:50:03 +02:00
|
|
|
Tasks Tasks
|
2019-12-08 02:44:09 +02:00
|
|
|
Silent bool
|
2020-08-04 00:18:38 +02:00
|
|
|
Dotenv []string
|
2020-08-17 21:25:17 +02:00
|
|
|
Run string
|
2022-09-08 19:22:44 +02:00
|
|
|
Interval string
|
2018-02-17 18:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements yaml.Unmarshaler interface
|
|
|
|
func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var taskfile struct {
|
2018-03-04 20:50:03 +02:00
|
|
|
Version string
|
|
|
|
Expansions int
|
2022-02-20 00:31:27 +02:00
|
|
|
Output Output
|
2019-09-09 03:26:24 +02:00
|
|
|
Method string
|
2021-01-01 23:27:50 +02:00
|
|
|
Includes *IncludedTaskfiles
|
2020-03-29 21:54:59 +02:00
|
|
|
Vars *Vars
|
|
|
|
Env *Vars
|
2018-03-04 20:50:03 +02:00
|
|
|
Tasks Tasks
|
2019-12-08 02:44:09 +02:00
|
|
|
Silent bool
|
2020-08-19 10:59:58 +02:00
|
|
|
Dotenv []string
|
2020-08-17 21:25:17 +02:00
|
|
|
Run string
|
2022-09-08 19:22:44 +02:00
|
|
|
Interval string
|
2018-02-17 18:22:18 +02:00
|
|
|
}
|
2022-09-08 19:22:44 +02:00
|
|
|
|
2018-02-17 18:22:18 +02:00
|
|
|
if err := unmarshal(&taskfile); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-08 19:22:44 +02:00
|
|
|
|
2018-02-17 18:22:18 +02:00
|
|
|
tf.Version = taskfile.Version
|
2018-03-04 20:50:03 +02:00
|
|
|
tf.Expansions = taskfile.Expansions
|
2018-04-15 16:11:07 +02:00
|
|
|
tf.Output = taskfile.Output
|
2019-09-09 03:26:24 +02:00
|
|
|
tf.Method = taskfile.Method
|
2018-09-10 03:29:29 +02:00
|
|
|
tf.Includes = taskfile.Includes
|
2018-03-04 20:39:14 +02:00
|
|
|
tf.Vars = taskfile.Vars
|
2019-01-02 16:05:40 +02:00
|
|
|
tf.Env = taskfile.Env
|
2018-02-17 18:22:18 +02:00
|
|
|
tf.Tasks = taskfile.Tasks
|
2019-12-08 02:44:09 +02:00
|
|
|
tf.Silent = taskfile.Silent
|
2020-08-04 00:18:38 +02:00
|
|
|
tf.Dotenv = taskfile.Dotenv
|
2020-08-17 21:25:17 +02:00
|
|
|
tf.Run = taskfile.Run
|
2022-09-08 19:22:44 +02:00
|
|
|
tf.Interval = taskfile.Interval
|
|
|
|
|
2018-03-04 20:50:03 +02:00
|
|
|
if tf.Expansions <= 0 {
|
|
|
|
tf.Expansions = 2
|
|
|
|
}
|
2020-04-05 16:08:49 +02:00
|
|
|
if tf.Vars == nil {
|
|
|
|
tf.Vars = &Vars{}
|
|
|
|
}
|
|
|
|
if tf.Env == nil {
|
|
|
|
tf.Env = &Vars{}
|
|
|
|
}
|
2018-02-17 18:22:18 +02:00
|
|
|
return nil
|
|
|
|
}
|
2020-05-17 20:42:27 +02:00
|
|
|
|
|
|
|
// ParsedVersion returns the version as a float64
|
|
|
|
func (tf *Taskfile) ParsedVersion() (float64, error) {
|
|
|
|
v, err := strconv.ParseFloat(tf.Version, 64)
|
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf(`task: Could not parse taskfile version "%s": %v`, tf.Version, err)
|
|
|
|
}
|
|
|
|
return v, nil
|
|
|
|
}
|