1
0
mirror of https://github.com/go-task/task.git synced 2025-06-17 00:17:51 +02:00

Envs should be overridable

System-wide environment variable should have priority. That's how it
works for .env files, so this is consistent.

Closes #425
This commit is contained in:
Andrey Nering
2021-01-12 11:32:49 -03:00
parent e086b654aa
commit c11672fca3
2 changed files with 14 additions and 2 deletions

View File

@ -2,6 +2,9 @@
## Unreleased
- Fixed a bug where an environment in a Taskfile was not always overridable
by the system environment
([#425](https://github.com/go-task/task/issues/425)).
- Fixed environment from .env files not being available as variables
([#379](https://github.com/go-task/task/issues/379)).

13
task.go
View File

@ -397,10 +397,19 @@ func getEnviron(t *taskfile.Task) []string {
}
environ := os.Environ()
for k, v := range t.Env.ToCacheMap() {
if s, ok := v.(string); ok {
environ = append(environ, fmt.Sprintf("%s=%s", k, s))
str, isString := v.(string)
if !isString {
continue
}
if _, alreadySet := os.LookupEnv(k); alreadySet {
continue
}
environ = append(environ, fmt.Sprintf("%s=%s", k, str))
}
return environ
}