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:
parent
b552cc2b12
commit
ef2695974d
10
README.md
10
README.md
@ -78,8 +78,8 @@ build:
|
|||||||
|
|
||||||
### OS specific task
|
### OS specific task
|
||||||
|
|
||||||
If you add a `Taskfile_{{GOOS}}` you can override or amend your taskfile based
|
If you add a `Taskfile_{{GOOS}}.yml` you can override or amend your taskfile
|
||||||
on the operating system.
|
based on the operating system.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@ -99,7 +99,11 @@ build:
|
|||||||
- echo "linux"
|
- 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
|
### Task directory
|
||||||
|
|
||||||
|
15
taskfile.go
15
taskfile.go
@ -42,12 +42,25 @@ func (e *Executor) readTaskfileData(path string) (tasks map[string]*Task, err er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) readTaskvars() error {
|
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 b, err := ioutil.ReadFile(file + ".yml"); err == nil {
|
||||||
if err := yaml.UnmarshalStrict(b, &e.taskvars); err != nil {
|
if err := yaml.UnmarshalStrict(b, &e.taskvars); err != nil {
|
||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user