MCPcopy Index your code
hub / github.com/go-task/task / DefaultDir

Function DefaultDir

internal/fsext/fs.go:16–38  ·  view source on GitHub ↗

DefaultDir will return the default directory given an entrypoint or directory. If the directory is set, it will ensure it is an absolute path and return it. If the entrypoint is set, but the directory is not, it will leave the directory blank. If both are empty, it will default the directory to the

(entrypoint, dir string)

Source from the content-addressed store, hash-verified

14// the directory blank. If both are empty, it will default the directory to the
15// current working directory.
16func DefaultDir(entrypoint, dir string) string {
17 // If the directory is set, ensure it is an absolute path
18 if dir != "" {
19 var err error
20 dir, err = filepath.Abs(dir)
21 if err != nil {
22 return ""
23 }
24 return dir
25 }
26
27 // If the entrypoint and dir are empty, we default the directory to the current working directory
28 if entrypoint == "" {
29 wd, err := os.Getwd()
30 if err != nil {
31 return ""
32 }
33 return wd
34 }
35
36 // If the entrypoint is set, but the directory is not, we leave the directory blank
37 return ""
38}
39
40// ResolveDir returns an absolute path to the directory that the task should be
41// run in. If the entrypoint and dir are BOTH set, then the Taskfile will not

Callers 3

NewNodeFunction · 0.92
NewRootNodeFunction · 0.92
TestDefaultDirFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestDefaultDirFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…