1
0
mirror of https://github.com/go-task/task.git synced 2025-12-01 22:52:02 +02:00

Add --init flag to create a new Taskfile

This commit is contained in:
Andrey Nering
2017-05-17 15:38:46 -03:00
parent 83f1b213fa
commit 2615000609
6 changed files with 59 additions and 1 deletions

29
init.go Normal file
View File

@@ -0,0 +1,29 @@
package task
import (
"io/ioutil"
"log"
"os"
)
const defaultTaskfile = `# github.com/go-task/task
default:
cmds:
- echo "Hello, World!"
`
func initTaskfile() {
for _, f := range []string{"Taskfile.yml", "Taskfile.toml", "Taskfile.json"} {
if _, err := os.Stat(f); err == nil {
log.Printf("A Taskfile already exists")
os.Exit(1)
return
}
}
if err := ioutil.WriteFile("Taskfile.yml", []byte(defaultTaskfile), 0666); err != nil {
log.Fatalf("%v", err)
}
log.Printf("Taskfile.yml created in the current directory")
}