InitTaskfile creates a new Taskfile at path. path can be either a file path or a directory path. If path is a directory, path/Taskfile.yml will be created. The final file path is always returned and may be different from the input path.
(path string)
| 21 | // |
| 22 | // The final file path is always returned and may be different from the input path. |
| 23 | func InitTaskfile(path string) (string, error) { |
| 24 | info, err := os.Stat(path) |
| 25 | if err == nil && !info.IsDir() { |
| 26 | return path, errors.TaskfileAlreadyExistsError{} |
| 27 | } |
| 28 | |
| 29 | if info != nil && info.IsDir() { |
| 30 | // path was a directory, check if there is a Taskfile already |
| 31 | if hasDefaultTaskfile(path) { |
| 32 | return path, errors.TaskfileAlreadyExistsError{} |
| 33 | } |
| 34 | path = filepathext.SmartJoin(path, defaultFilename) |
| 35 | } |
| 36 | |
| 37 | if err := os.WriteFile(path, []byte(DefaultTaskfile), 0o644); err != nil { |
| 38 | return path, err |
| 39 | } |
| 40 | return path, nil |
| 41 | } |
| 42 | |
| 43 | func hasDefaultTaskfile(dir string) bool { |
| 44 | for _, name := range taskfile.DefaultTaskfiles { |
nothing calls this directly
no test coverage detected
searching dependent graphs…