Skip to content

Commit ff8c913

Browse files
committed
chore: changelog and minor adjustments for go-task#2018
1 parent 0e23404 commit ff8c913

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Made `--init` less verbose by default and respect `--silent` and `--verbose`
66
flags (#2009, #2011 by @HeCorr).
7+
- `--init` now accepts a file name or directory as an argument (#2008, #2018 by
8+
@HeCorr).
79
- Fix a bug where an HTTP node's location was being mutated incorrectly (#2007
810
by @jeongukjae).
911
- Fixed a bug where allowed values didn't work with dynamic var (#2032, #2033 by

cmd/task/task.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
fp "path/filepath"
7+
"path/filepath"
88
"strings"
99

1010
"github.com/spf13/pflag"
@@ -87,11 +87,11 @@ func run() error {
8787
if len(args) > 0 {
8888
name := args[0]
8989
if filepathext.IsExtOnly(name) {
90-
name = filepathext.SmartJoin(fp.Dir(name), "Taskfile"+fp.Ext(name))
90+
name = filepathext.SmartJoin(filepath.Dir(name), "Taskfile"+filepath.Ext(name))
9191
}
9292
path = filepathext.SmartJoin(wd, name)
9393
}
94-
finalPath, err := task.InitTaskfile(os.Stdout, path)
94+
finalPath, err := task.InitTaskfile(path)
9595
if err != nil {
9696
return err
9797
}

init.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package task
22

33
import (
4-
"io"
54
"os"
65

76
"github.com/go-task/task/v3/errors"
@@ -22,22 +21,22 @@ tasks:
2221
silent: true
2322
`
2423

25-
const DefaultTaskFilename = "Taskfile.yml"
24+
const defaultTaskFilename = "Taskfile.yml"
2625

2726
// InitTaskfile creates a new Taskfile at path.
2827
//
2928
// path can be either a file path or a directory path.
3029
// If path is a directory, path/Taskfile.yml will be created.
3130
//
3231
// The final file path is always returned and may be different from the input path.
33-
func InitTaskfile(w io.Writer, path string) (string, error) {
32+
func InitTaskfile(path string) (string, error) {
3433
fi, err := os.Stat(path)
3534
if err == nil && !fi.IsDir() {
3635
return path, errors.TaskfileAlreadyExistsError{}
3736
}
3837

3938
if fi != nil && fi.IsDir() {
40-
path = filepathext.SmartJoin(path, DefaultTaskFilename)
39+
path = filepathext.SmartJoin(path, defaultTaskFilename)
4140
// path was a directory, so check if Taskfile.yml exists in it
4241
if _, err := os.Stat(path); err == nil {
4342
return path, errors.TaskfileAlreadyExistsError{}

init_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package task_test
22

33
import (
4-
"io"
54
"os"
65
"testing"
76

@@ -20,7 +19,7 @@ func TestInitDir(t *testing.T) {
2019
t.Errorf("Taskfile.yml should not exist")
2120
}
2221

23-
if _, err := task.InitTaskfile(io.Discard, dir); err != nil {
22+
if _, err := task.InitTaskfile(dir); err != nil {
2423
t.Error(err)
2524
}
2625

@@ -42,7 +41,7 @@ func TestInitFile(t *testing.T) {
4241
t.Errorf("Tasks.yml should not exist")
4342
}
4443

45-
if _, err := task.InitTaskfile(io.Discard, file); err != nil {
44+
if _, err := task.InitTaskfile(file); err != nil {
4645
t.Error(err)
4746
}
4847

0 commit comments

Comments
 (0)