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)
| 14 | // the directory blank. If both are empty, it will default the directory to the |
| 15 | // current working directory. |
| 16 | func 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 |
no outgoing calls
searching dependent graphs…