1
0
mirror of https://github.com/go-task/task.git synced 2025-01-22 05:10:17 +02:00
2021-12-20 20:00:34 -06:00

38 lines
622 B
Go

package task
import (
"fmt"
"io"
"os"
"path/filepath"
)
const defaultTaskfile = `# https://taskfile.dev
version: '3'
vars:
GREETING: Hello, World!
tasks:
default:
cmds:
- echo "{{.GREETING}}"
silent: true
`
// InitTaskfile Taskfile creates a new Taskfile
func InitTaskfile(w io.Writer, dir string) error {
f := filepath.Join(dir, "Taskfile.yml")
if _, err := os.Stat(f); err == nil {
return ErrTaskfileAlreadyExists
}
if err := os.WriteFile(f, []byte(defaultTaskfile), 0644); err != nil {
return err
}
fmt.Fprintf(w, "Taskfile.yml created in the current directory\n")
return nil
}