1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00

os specific Taskvars file

Now it's possible to have Taskfile_windows.yml or Taskvars_linux.yml
(and others).

Asked in a comment in #46
This commit is contained in:
Andrey Nering 2017-07-15 13:46:35 -03:00
parent b552cc2b12
commit ef2695974d
2 changed files with 21 additions and 4 deletions

View File

@ -78,8 +78,8 @@ build:
### OS specific task
If you add a `Taskfile_{{GOOS}}` you can override or amend your taskfile based
on the operating system.
If you add a `Taskfile_{{GOOS}}.yml` you can override or amend your taskfile
based on the operating system.
Example:
@ -99,7 +99,11 @@ build:
- echo "linux"
```
Will print out `linux` and not default
Will print out `linux` and not default.
It's also possible to have OS specific `Taskvars.yml` file, like
`Taskvars_windows.yml` or `Taskvars_darwin.yml`. See the
[variables section](#variables) below.
### Task directory

View File

@ -42,12 +42,25 @@ func (e *Executor) readTaskfileData(path string) (tasks map[string]*Task, err er
}
func (e *Executor) readTaskvars() error {
file := filepath.Join(e.Dir, TaskvarsFilePath)
var (
file = filepath.Join(e.Dir, TaskvarsFilePath)
osSpecificFile = fmt.Sprintf("%s_%s", file, runtime.GOOS)
)
if b, err := ioutil.ReadFile(file + ".yml"); err == nil {
if err := yaml.UnmarshalStrict(b, &e.taskvars); err != nil {
return err
}
}
if b, err := ioutil.ReadFile(osSpecificFile + ".yml"); err == nil {
osTaskvars := make(Vars, 10)
if err := yaml.UnmarshalStrict(b, &osTaskvars); err != nil {
return err
}
for k, v := range osTaskvars {
e.taskvars[k] = v
}
}
return nil
}