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:
@@ -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
|
||||
|
7
init.go
7
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
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user