1
0
mirror of https://github.com/go-task/task.git synced 2025-08-08 22:36:57 +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 {
log.Fatal(err)
}
if err := task.InitTaskfile(wd); err != nil {
if err := task.InitTaskfile(os.Stdout, wd); err != nil {
log.Fatal(err)
}
return

View File

@@ -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
}

View File

@@ -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)
}