1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00

custom stdout for InitTaskfile func

This commit is contained in:
Andrey Nering
2017-07-30 19:29:49 -03:00
parent dc1ec77da5
commit bb1aff84cf
3 changed files with 6 additions and 5 deletions

View File

@@ -73,7 +73,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
if err := task.InitTaskfile(wd); err != nil { if err := task.InitTaskfile(os.Stdout, wd); err != nil {
log.Fatal(err) log.Fatal(err)
} }
return return

View File

@@ -1,8 +1,9 @@
package task package task
import ( import (
"fmt"
"io"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"path/filepath" "path/filepath"
) )
@@ -15,7 +16,7 @@ default:
` `
// InitTaskfile Taskfile creates a new Taskfile // InitTaskfile Taskfile creates a new Taskfile
func InitTaskfile(path string) error { func InitTaskfile(w io.Writer, path string) error {
for _, f := range []string{"Taskfile.yml", "Taskfile.toml", "Taskfile.json"} { for _, f := range []string{"Taskfile.yml", "Taskfile.toml", "Taskfile.json"} {
f = filepath.Join(path, f) f = filepath.Join(path, f)
if _, err := os.Stat(f); err == nil { if _, err := os.Stat(f); err == nil {
@@ -27,6 +28,6 @@ func InitTaskfile(path string) error {
if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0666); err != nil { if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0666); err != nil {
return err return err
} }
log.Printf("Taskfile.yml created in the current directory") fmt.Fprintf(w, "Taskfile.yml created in the current directory\n")
return nil return nil
} }

View File

@@ -289,7 +289,7 @@ func TestInit(t *testing.T) {
t.Errorf("Taskfile.yml should not exists") t.Errorf("Taskfile.yml should not exists")
} }
if err := task.InitTaskfile(dir); err != nil { if err := task.InitTaskfile(ioutil.Discard, dir); err != nil {
t.Error(err) t.Error(err)
} }