diff --git a/cmd/task/task.go b/cmd/task/task.go index 77941d79da..8288ed7477 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -97,25 +97,27 @@ func main() { } var ( - versionFlag bool - init bool - list bool - listHidden bool - withDeps bool - status bool - force bool - watch bool - verbose bool - silent bool - dry bool - update bool - dir string + versionFlag bool + init bool + list bool + listHidden bool + withDeps bool + status bool + force bool + watch bool + verbose bool + taskfileLocation string + silent bool + dry bool + update bool + dir string ) pflag.BoolVar(&versionFlag, "version", false, "show Task version") pflag.BoolVarP(&init, "init", "i", false, "creates a new Taskfile.yml in the current folder") pflag.BoolVarP(&list, "list", "l", false, "lists tasks of current Taskfile") pflag.BoolVar(&update, "update", false, "selfupdate task") + pflag.StringVarP(&taskfileLocation, "config", "c", "Taskfile.yml", "Specify taskfile location") pflag.BoolVar(&listHidden, "list-hidden", false, "lists all tasks") pflag.BoolVar(&withDeps, "with-deps", false, "list all tasks with dependencies") @@ -157,12 +159,13 @@ func main() { } e := task.Executor{ - Force: force, - Watch: watch, - Verbose: verbose, - Silent: silent, - Dir: dir, - Dry: dry, + Force: force, + Watch: watch, + Verbose: verbose, + Silent: silent, + Dir: dir, + Dry: dry, + TaskfileLocation: taskfileLocation, Context: ctx, diff --git a/internal/taskfile/read/taskfile.go b/internal/taskfile/read/taskfile.go index 6e8b80e382..5fbbfbb1ff 100644 --- a/internal/taskfile/read/taskfile.go +++ b/internal/taskfile/read/taskfile.go @@ -22,8 +22,14 @@ var ( ) // Taskfile reads a Taskfile for a given directory -func Taskfile(dir string) (*taskfile.Taskfile, error) { +func Taskfile(dir, location string) (*taskfile.Taskfile, error) { path := filepath.Join(dir, "Taskfile.yml") + if location != "" { + path = filepath.Join(dir, location) + } + if location != "" && filepath.IsAbs(location) { + path = location + } if _, err := os.Stat(path); err != nil { return nil, ErrNoTaskfileFound } diff --git a/task.go b/task.go index 045398c3fa..47ba24697c 100644 --- a/task.go +++ b/task.go @@ -29,13 +29,14 @@ const ( // Executor executes a Taskfile type Executor struct { - Taskfile *taskfile.Taskfile - Dir string - Force bool - Watch bool - Verbose bool - Silent bool - Dry bool + Taskfile *taskfile.Taskfile + Dir string + Force bool + Watch bool + Verbose bool + Silent bool + Dry bool + TaskfileLocation string Context context.Context @@ -78,7 +79,7 @@ func (e *Executor) Run(calls ...taskfile.Call) error { // Setup setups Executor's internal state func (e *Executor) Setup() error { var err error - e.Taskfile, err = read.Taskfile(e.Dir) + e.Taskfile, err = read.Taskfile(e.Dir, e.TaskfileLocation) if err != nil { return err }