1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00

Improve --init flag

- Update generated Taskfile to version 2
- Don't loop anymore on extensions since we only support YAML
- Use 644 for file permission
This commit is contained in:
Andrey Nering 2018-03-04 16:17:51 -03:00
parent 51998f706f
commit 7c02097d93

27
init.go
View File

@ -10,22 +10,27 @@ import (
const defaultTaskfile = `# github.com/go-task/task const defaultTaskfile = `# github.com/go-task/task
default: version: '2'
cmds:
- echo "Hello, World!" vars:
GREETING: Hello, World!
tasks:
default:
cmds:
- echo "{{.GREETING}}"
silent: true
` `
// InitTaskfile Taskfile creates a new Taskfile // InitTaskfile Taskfile creates a new Taskfile
func InitTaskfile(w io.Writer, path string) error { func InitTaskfile(w io.Writer, dir string) error {
for _, f := range []string{"Taskfile.yml", "Taskfile.toml", "Taskfile.json"} { f := filepath.Join(dir, "Taskfile.yml")
f = filepath.Join(path, f)
if _, err := os.Stat(f); err == nil { if _, err := os.Stat(f); err == nil {
return ErrTaskfileAlreadyExists return ErrTaskfileAlreadyExists
}
} }
f := filepath.Join(path, "Taskfile.yml") if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0644); err != nil {
if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0666); err != nil {
return err return err
} }
fmt.Fprintf(w, "Taskfile.yml created in the current directory\n") fmt.Fprintf(w, "Taskfile.yml created in the current directory\n")