1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00
task/init.go
Andrey Nering ecfd8e8a62 change all tests to call functions instead of binary directly
I had to temporarely hack github.com/mvdan/sh to fix dir handling
2017-07-01 15:32:13 -03:00

33 lines
656 B
Go

package task
import (
"io/ioutil"
"log"
"os"
"path/filepath"
)
const defaultTaskfile = `# github.com/go-task/task
default:
cmds:
- echo "Hello, World!"
`
// InitTaskfile Taskfile creates a new Taskfile
func InitTaskfile(path string) error {
for _, f := range []string{"Taskfile.yml", "Taskfile.toml", "Taskfile.json"} {
f = filepath.Join(path, f)
if _, err := os.Stat(f); err == nil {
return ErrTaskfileAlreadyExists
}
}
f := filepath.Join(path, "Taskfile.yml")
if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0666); err != nil {
return err
}
log.Printf("Taskfile.yml created in the current directory")
return nil
}