2017-05-17 15:38:46 -03:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
2017-07-30 19:29:49 -03:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2017-05-17 15:38:46 -03:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2017-07-01 15:32:13 -03:00
|
|
|
"path/filepath"
|
2017-05-17 15:38:46 -03:00
|
|
|
)
|
|
|
|
|
2019-03-04 23:23:30 -03:00
|
|
|
const defaultTaskfile = `# https://taskfile.dev
|
2017-05-17 15:38:46 -03:00
|
|
|
|
2019-08-19 21:01:36 +02:00
|
|
|
version: '3'
|
2018-03-04 16:17:51 -03:00
|
|
|
|
|
|
|
vars:
|
|
|
|
GREETING: Hello, World!
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
default:
|
|
|
|
cmds:
|
|
|
|
- echo "{{.GREETING}}"
|
|
|
|
silent: true
|
2017-05-17 15:38:46 -03:00
|
|
|
`
|
|
|
|
|
2017-06-04 16:02:04 -03:00
|
|
|
// InitTaskfile Taskfile creates a new Taskfile
|
2018-03-04 16:17:51 -03: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 15:38:46 -03:00
|
|
|
}
|
|
|
|
|
2018-03-04 16:17:51 -03:00
|
|
|
if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0644); err != nil {
|
2017-06-04 16:02:04 -03:00
|
|
|
return err
|
2017-05-17 15:38:46 -03:00
|
|
|
}
|
2017-07-30 19:29:49 -03:00
|
|
|
fmt.Fprintf(w, "Taskfile.yml created in the current directory\n")
|
2017-06-04 16:02:04 -03:00
|
|
|
return nil
|
2017-05-17 15:38:46 -03:00
|
|
|
}
|