From ff8c913ce7cb572741d46ee47dd5f81a04fd74a8 Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Mon, 10 Feb 2025 11:24:32 +0000 Subject: [PATCH] chore: changelog and minor adjustments for #2018 --- CHANGELOG.md | 2 ++ cmd/task/task.go | 6 +++--- init.go | 7 +++---- init_test.go | 5 ++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2fde89ecb..c335f91787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Made `--init` less verbose by default and respect `--silent` and `--verbose` flags (#2009, #2011 by @HeCorr). +- `--init` now accepts a file name or directory as an argument (#2008, #2018 by + @HeCorr). - Fix a bug where an HTTP node's location was being mutated incorrectly (#2007 by @jeongukjae). - Fixed a bug where allowed values didn't work with dynamic var (#2032, #2033 by diff --git a/cmd/task/task.go b/cmd/task/task.go index e59273b48f..060f9716f0 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "os" - fp "path/filepath" + "path/filepath" "strings" "github.com/spf13/pflag" @@ -87,11 +87,11 @@ func run() error { if len(args) > 0 { name := args[0] if filepathext.IsExtOnly(name) { - name = filepathext.SmartJoin(fp.Dir(name), "Taskfile"+fp.Ext(name)) + name = filepathext.SmartJoin(filepath.Dir(name), "Taskfile"+filepath.Ext(name)) } path = filepathext.SmartJoin(wd, name) } - finalPath, err := task.InitTaskfile(os.Stdout, path) + finalPath, err := task.InitTaskfile(path) if err != nil { return err } diff --git a/init.go b/init.go index 04f0c0b766..f5bac631c5 100644 --- a/init.go +++ b/init.go @@ -1,7 +1,6 @@ package task import ( - "io" "os" "github.com/go-task/task/v3/errors" @@ -22,7 +21,7 @@ tasks: silent: true ` -const DefaultTaskFilename = "Taskfile.yml" +const defaultTaskFilename = "Taskfile.yml" // InitTaskfile creates a new Taskfile at path. // @@ -30,14 +29,14 @@ const DefaultTaskFilename = "Taskfile.yml" // If path is a directory, path/Taskfile.yml will be created. // // The final file path is always returned and may be different from the input path. -func InitTaskfile(w io.Writer, path string) (string, error) { +func InitTaskfile(path string) (string, error) { fi, err := os.Stat(path) if err == nil && !fi.IsDir() { return path, errors.TaskfileAlreadyExistsError{} } if fi != nil && fi.IsDir() { - path = filepathext.SmartJoin(path, DefaultTaskFilename) + path = filepathext.SmartJoin(path, defaultTaskFilename) // path was a directory, so check if Taskfile.yml exists in it if _, err := os.Stat(path); err == nil { return path, errors.TaskfileAlreadyExistsError{} diff --git a/init_test.go b/init_test.go index ce401c0881..41095d65e1 100644 --- a/init_test.go +++ b/init_test.go @@ -1,7 +1,6 @@ package task_test import ( - "io" "os" "testing" @@ -20,7 +19,7 @@ func TestInitDir(t *testing.T) { t.Errorf("Taskfile.yml should not exist") } - if _, err := task.InitTaskfile(io.Discard, dir); err != nil { + if _, err := task.InitTaskfile(dir); err != nil { t.Error(err) } @@ -42,7 +41,7 @@ func TestInitFile(t *testing.T) { t.Errorf("Tasks.yml should not exist") } - if _, err := task.InitTaskfile(io.Discard, file); err != nil { + if _, err := task.InitTaskfile(file); err != nil { t.Error(err) }