2017-05-17 20:38:46 +02:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
2017-07-01 20:32:13 +02:00
|
|
|
"path/filepath"
|
2017-05-17 20:38:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2017-07-01 20:32:13 +02:00
|
|
|
func InitTaskfile(path string) error {
|
2017-05-17 20:38:46 +02:00
|
|
|
for _, f := range []string{"Taskfile.yml", "Taskfile.toml", "Taskfile.json"} {
|
2017-07-01 20:32:13 +02:00
|
|
|
f = filepath.Join(path, f)
|
2017-05-17 20:38:46 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-01 20:32:13 +02:00
|
|
|
f := filepath.Join(path, "Taskfile.yml")
|
|
|
|
if err := ioutil.WriteFile(f, []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
|
|
|
}
|