Skip to content

Commit

Permalink
chore: changelog and minor adjustments for #2018
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Feb 10, 2025
1 parent 0e23404 commit ff8c913
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"
"os"
fp "path/filepath"
"path/filepath"
"strings"

"github.com/spf13/pflag"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions init.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package task

import (
"io"
"os"

"github.com/go-task/task/v3/errors"
Expand All @@ -22,22 +21,22 @@ tasks:
silent: true
`

const DefaultTaskFilename = "Taskfile.yml"
const defaultTaskFilename = "Taskfile.yml"

// InitTaskfile creates a new Taskfile at path.
//
// path can be either a file path or a directory path.
// 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{}
Expand Down
5 changes: 2 additions & 3 deletions init_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package task_test

import (
"io"
"os"
"testing"

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

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

Expand Down

0 comments on commit ff8c913

Please sign in to comment.