Skip to content

Commit

Permalink
feat: enable root remote taskfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Sep 23, 2023
1 parent 9dc7502 commit 8d03ad3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
5 changes: 0 additions & 5 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -202,10 +201,6 @@ func run() error {
if flags.dir != "" && flags.entrypoint != "" {
return errors.New("task: You can't set both --dir and --taskfile")
}
if flags.entrypoint != "" {
flags.dir = filepath.Dir(flags.entrypoint)
flags.entrypoint = filepath.Base(flags.entrypoint)
}

if flags.output.Name != "group" {
if flags.output.Group.Begin != "" {
Expand Down
13 changes: 11 additions & 2 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,17 @@ func (e *Executor) Setup() error {
}

func (e *Executor) setCurrentDir() error {
// If the entrypoint is already set, we don't need to do anything
if e.Entrypoint != "" {
if e.Entrypoint != "" && e.Dir != "" {
return errors.New("cannot set both entrypoint and dir")
}

// Remove the file protocol prefix if it exists
e.Entrypoint = strings.TrimPrefix(e.Entrypoint, "file://")

// If the entrypoint is already set and isn't a remote file
if e.Entrypoint != "" && !strings.Contains(e.Entrypoint, "://") {
e.Dir = filepath.Dir(e.Entrypoint)
e.Entrypoint = filepath.Base(e.Entrypoint)
return nil
}

Expand Down
17 changes: 6 additions & 11 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (fct fileContentTest) Run(t *testing.T) {

for name, expectContent := range fct.Files {
t.Run(fct.name(name), func(t *testing.T) {
path := filepathext.SmartJoin(fct.Dir, name)
path := filepathext.SmartJoin(e.Dir, name)
b, err := os.ReadFile(path)
require.NoError(t, err, "Error reading file")
s := string(b)
Expand Down Expand Up @@ -1162,8 +1162,7 @@ func TestIncludesOptionalExplicitFalse(t *testing.T) {

func TestIncludesFromCustomTaskfile(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/includes_yaml",
Entrypoint: "Custom.ext",
Entrypoint: "testdata/includes_yaml/Custom.ext",
Target: "default",
TrimSpace: true,
Files: map[string]string{
Expand Down Expand Up @@ -1525,16 +1524,12 @@ func TestDotenvShouldIncludeAllEnvFiles(t *testing.T) {
}

func TestDotenvShouldErrorWhenIncludingDependantDotenvs(t *testing.T) {
const dir = "testdata/dotenv/error_included_envs"
const entry = "Taskfile.yml"

var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Entrypoint: entry,
Summary: true,
Stdout: &buff,
Stderr: &buff,
Dir: "testdata/dotenv/error_included_envs",
Summary: true,
Stdout: &buff,
Stderr: &buff,
}

err := e.Setup()
Expand Down

0 comments on commit 8d03ad3

Please sign in to comment.