Skip to content

Commit

Permalink
refactor: slightly improved NewBaseNode API
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Mar 4, 2024
1 parent 6e6e262 commit f420aca
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions taskfile/node_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type (
}
)

func NewBaseNode(opts ...NodeOption) *BaseNode {
func NewBaseNode(dir string, opts ...NodeOption) *BaseNode {
node := &BaseNode{
parent: nil,
optional: false,
dir: "",
dir: dir,
}

// Apply options
Expand Down
5 changes: 2 additions & 3 deletions taskfile/node_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ type FileNode struct {

func NewFileNode(l *logger.Logger, entrypoint, dir string, opts ...NodeOption) (*FileNode, error) {
var err error
base := NewBaseNode(opts...)
entrypoint, dir, err = resolveFileNodeEntrypointAndDir(l, entrypoint, dir)
base := NewBaseNode(dir, opts...)
entrypoint, base.dir, err = resolveFileNodeEntrypointAndDir(l, entrypoint, base.dir)
if err != nil {
return nil, err
}
base.dir = dir
return &FileNode{
BaseNode: base,
Entrypoint: entrypoint,
Expand Down
3 changes: 1 addition & 2 deletions taskfile/node_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ type HTTPNode struct {
}

func NewHTTPNode(l *logger.Logger, entrypoint, dir string, insecure bool, opts ...NodeOption) (*HTTPNode, error) {
base := NewBaseNode(opts...)
base.dir = dir
base := NewBaseNode(dir, opts...)
url, err := url.Parse(entrypoint)
if err != nil {
return nil, err
Expand Down
4 changes: 1 addition & 3 deletions taskfile/node_stdin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ type StdinNode struct {
}

func NewStdinNode(dir string) (*StdinNode, error) {
base := NewBaseNode()
base.dir = dir
return &StdinNode{
BaseNode: base,
BaseNode: NewBaseNode(dir),
}, nil
}

Expand Down

0 comments on commit f420aca

Please sign in to comment.