mirror of
https://github.com/go-task/task.git
synced 2025-04-19 23:02:17 +03:00
chore: changelog and minor adjustments for #2018
This commit is contained in:
parent
0e23404d23
commit
ff8c913ce7
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
7
init.go
7
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{}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user