diff --git a/README.md b/README.md index 4ed5ef46..5718c652 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/taskfile.go b/taskfile.go index 34dbc9e6..56aec576 100644 --- a/taskfile.go +++ b/taskfile.go @@ -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 }