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