MCPcopy Create free account
hub / github.com/go-task/task / InitTaskfile

Function InitTaskfile

init.go:23–41  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

21//
22// The final file path is always returned and may be different from the input path.
23func 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
43func hasDefaultTaskfile(dir string) bool {
44 for _, name := range taskfile.DefaultTaskfiles {

Callers

nothing calls this directly

Calls 2

SmartJoinFunction · 0.92
hasDefaultTaskfileFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…