Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for Taskfiles in parent directories #289

Closed
Chi-teck opened this issue Feb 4, 2020 · 7 comments · Fixed by #920
Closed

Search for Taskfiles in parent directories #289

Chi-teck opened this issue Feb 4, 2020 · 7 comments · Fixed by #920
Labels
type: feature A new feature or functionality.

Comments

@Chi-teck
Copy link

Chi-teck commented Feb 4, 2020

Is it possible to run Task commands from child directories without specifying a path to the Taskfile explicitly (task -t ../.././Taskfile.yml)?

@andreynering andreynering added the type: feature A new feature or functionality. label Feb 9, 2020
@andreynering
Copy link
Member

Hi @Chi-teck, and thanks for opening this issue!

This is a good idea indeed: searching for parent directories if a Taskfile isn't found in the current one.

I plan to work on this eventually, but contributions are also welcome.

@Chi-teck
Copy link
Author

The most noticeable example of such feature is Git. You don't have to cd to project root repository to execute Git commands.

@Chi-teck
Copy link
Author

Meanwhile the following Bash function can be used as a workaround.

#
# Task wrapper that searches for task file recursively.
#
function task {

  # Do not proceed if '--taskfile' option was supplied.
  for i in "$@"; do
    if [[ $i == -t* || $i == --taskfile=* ]]; then
      command task "$@"
      return $?
    fi
  done

  local DIR=$(pwd)
  while true; do
    if [[ $DIR == '/' ]]; then
      command task "$@"
      return $?
    fi

    if [[ -f $DIR/Taskfile.yml ]]; then
      command task --taskfile="$DIR"/Taskfile.yml "$@"
      return $?
    fi

    DIR=$(dirname "$DIR")
  done
}

@andreynering andreynering changed the title Search Taskfile in parrent directories Search for Taskfiles in parent directories Mar 1, 2020
@stephencheng

This comment was marked as off-topic.

@marco-m
Copy link
Contributor

marco-m commented Aug 18, 2020

Two example of tools with this behavior:

@ibes
Copy link

ibes commented Sep 29, 2022

Would there be a way - similar to the bash file - where I can tell for my project to always attach my project taskfile in the command?

Hm - likely the flaw on this way is, that the bash command needs to be global or can only be used by on project.
As otherwise: How does the script know if it is supposed to do stuff.

There could be a config file for the bash script.

If somewhere within this path (=project), add taskfile config x
If somewhere within this path (=project), add taskfile config y

Not sure if that really is a solution, but maybe it's easy enough.

Would love to see this feature.
Unfortunately I am not skilled to contribute.

@marco-m
Copy link
Contributor

marco-m commented Dec 6, 2022

Nice one! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature or functionality.
Projects
None yet
5 participants