Skip to content

Commit ef26959

Browse files
committed
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
1 parent b552cc2 commit ef26959

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ build:
7878
7979
### OS specific task
8080
81-
If you add a `Taskfile_{{GOOS}}` you can override or amend your taskfile based
82-
on the operating system.
81+
If you add a `Taskfile_{{GOOS}}.yml` you can override or amend your taskfile
82+
based on the operating system.
8383

8484
Example:
8585

@@ -99,7 +99,11 @@ build:
9999
- echo "linux"
100100
```
101101

102-
Will print out `linux` and not default
102+
Will print out `linux` and not default.
103+
104+
It's also possible to have OS specific `Taskvars.yml` file, like
105+
`Taskvars_windows.yml` or `Taskvars_darwin.yml`. See the
106+
[variables section](#variables) below.
103107

104108
### Task directory
105109

taskfile.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,25 @@ func (e *Executor) readTaskfileData(path string) (tasks map[string]*Task, err er
4242
}
4343

4444
func (e *Executor) readTaskvars() error {
45-
file := filepath.Join(e.Dir, TaskvarsFilePath)
45+
var (
46+
file = filepath.Join(e.Dir, TaskvarsFilePath)
47+
osSpecificFile = fmt.Sprintf("%s_%s", file, runtime.GOOS)
48+
)
4649

4750
if b, err := ioutil.ReadFile(file + ".yml"); err == nil {
4851
if err := yaml.UnmarshalStrict(b, &e.taskvars); err != nil {
4952
return err
5053
}
5154
}
55+
56+
if b, err := ioutil.ReadFile(osSpecificFile + ".yml"); err == nil {
57+
osTaskvars := make(Vars, 10)
58+
if err := yaml.UnmarshalStrict(b, &osTaskvars); err != nil {
59+
return err
60+
}
61+
for k, v := range osTaskvars {
62+
e.taskvars[k] = v
63+
}
64+
}
5265
return nil
5366
}

0 commit comments

Comments
 (0)