From bb1aff84cfb11f24f287accc57e8423195f22df3 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 30 Jul 2017 19:29:49 -0300 Subject: [PATCH] custom stdout for InitTaskfile func --- cmd/task/task.go | 2 +- init.go | 7 ++++--- task_test.go | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/task/task.go b/cmd/task/task.go index 2323ef1f..421d1a03 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -73,7 +73,7 @@ func main() { if err != nil { log.Fatal(err) } - if err := task.InitTaskfile(wd); err != nil { + if err := task.InitTaskfile(os.Stdout, wd); err != nil { log.Fatal(err) } return diff --git a/init.go b/init.go index 0b66479f..8717f505 100644 --- a/init.go +++ b/init.go @@ -1,8 +1,9 @@ package task import ( + "fmt" + "io" "io/ioutil" - "log" "os" "path/filepath" ) @@ -15,7 +16,7 @@ default: ` // 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"} { f = filepath.Join(path, f) 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 { return err } - log.Printf("Taskfile.yml created in the current directory") + fmt.Fprintf(w, "Taskfile.yml created in the current directory\n") return nil } diff --git a/task_test.go b/task_test.go index 83faefde..28d27432 100644 --- a/task_test.go +++ b/task_test.go @@ -289,7 +289,7 @@ func TestInit(t *testing.T) { 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) }