2017-05-17 20:38:46 +02:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
2017-07-31 00:29:49 +02:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2017-05-17 20:38:46 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"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
|
|
|
|
|
2018-03-04 21:17:51 +02:00
|
|
|
version: '2'
|
|
|
|
|
|
|
|
vars:
|
|
|
|
GREETING: Hello, World!
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
default:
|
|
|
|
cmds:
|
|
|
|
- echo "{{.GREETING}}"
|
|
|
|
silent: true
|
2017-05-17 20:38:46 +02:00
|
|
|
`
|
|
|
|
|
2017-06-04 21:02:04 +02:00
|
|
|
// InitTaskfile Taskfile creates a new Taskfile
|
2018-03-04 21:17:51 +02:00
|
|
|
func InitTaskfile(w io.Writer, dir string) error {
|
|
|
|
f := filepath.Join(dir, "Taskfile.yml")
|
|
|
|
|
|
|
|
if _, err := os.Stat(f); err == nil {
|
|
|
|
return ErrTaskfileAlreadyExists
|
2017-05-17 20:38:46 +02:00
|
|
|
}
|
|
|
|
|
2018-03-04 21:17:51 +02:00
|
|
|
if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0644); err != nil {
|
2017-06-04 21:02:04 +02:00
|
|
|
return err
|
2017-05-17 20:38:46 +02:00
|
|
|
}
|
2017-07-31 00:29:49 +02:00
|
|
|
fmt.Fprintf(w, "Taskfile.yml created in the current directory\n")
|
2017-06-04 21:02:04 +02:00
|
|
|
return nil
|
2017-05-17 20:38:46 +02:00
|
|
|
}
|