mirror of
https://github.com/go-task/task.git
synced 2024-12-14 10:52:43 +02:00
4b6c79aca5
* feat: experiment taskfile envs take precedence over os envs * fix test * fix typo Co-authored-by: Andrey Nering <andrey@nering.com.br> * docs: add p about default --------- Co-authored-by: Andrey Nering <andrey@nering.com.br>
39 lines
642 B
Go
39 lines
642 B
Go
package env
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/go-task/task/v3/internal/experiments"
|
|
"github.com/go-task/task/v3/taskfile/ast"
|
|
)
|
|
|
|
func Get(t *ast.Task) []string {
|
|
if t.Env == nil {
|
|
return nil
|
|
}
|
|
environ := os.Environ()
|
|
for k, v := range t.Env.ToCacheMap() {
|
|
if !isTypeAllowed(v) {
|
|
continue
|
|
}
|
|
if !experiments.EnvPrecedence.Enabled {
|
|
if _, alreadySet := os.LookupEnv(k); alreadySet {
|
|
continue
|
|
}
|
|
}
|
|
environ = append(environ, fmt.Sprintf("%s=%v", k, v))
|
|
}
|
|
|
|
return environ
|
|
}
|
|
|
|
func isTypeAllowed(v any) bool {
|
|
switch v.(type) {
|
|
case string, bool, int, float32, float64:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|