MCPcopy
hub / github.com/go-task/task / Dotenv

Function Dotenv

taskfile/dotenv.go:14–41  ·  view source on GitHub ↗
(vars *ast.Vars, tf *ast.Taskfile, dir string)

Source from the content-addressed store, hash-verified

12)
13
14func Dotenv(vars *ast.Vars, tf *ast.Taskfile, dir string) (*ast.Vars, error) {
15 env := ast.NewVars()
16 cache := &templater.Cache{Vars: vars}
17
18 for _, dotEnvPath := range tf.Dotenv {
19 dotEnvPath = templater.Replace(dotEnvPath, cache)
20 if dotEnvPath == "" {
21 continue
22 }
23 dotEnvPath = filepathext.SmartJoin(dir, dotEnvPath)
24
25 if _, err := os.Stat(dotEnvPath); os.IsNotExist(err) {
26 continue
27 }
28
29 envs, err := godotenv.Read(dotEnvPath)
30 if err != nil {
31 return nil, fmt.Errorf("error reading env file %s: %w", dotEnvPath, err)
32 }
33 for key, value := range envs {
34 if _, ok := env.Get(key); !ok {
35 env.Set(key, ast.Var{Value: value})
36 }
37 }
38 }
39
40 return env, nil
41}

Callers 1

readDotEnvFilesMethod · 0.92

Calls 6

GetMethod · 0.95
SetMethod · 0.95
NewVarsFunction · 0.92
ReplaceFunction · 0.92
SmartJoinFunction · 0.92
ReadMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…