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

"default" task from included taskfile should be executed when no task name is provided #661

Closed
ankushg opened this issue Jan 23, 2022 · 7 comments
Labels
type: enhancement A change to an existing feature or functionality.

Comments

@ankushg
Copy link

ankushg commented Jan 23, 2022

I really like the behavior that

If you omit a task name, “default” will be assumed.

Unfortunately, it doen't seem to play well with included taskfiles.

For example, if I have a root Taskfile.yml with the following contents:

version: '3'

includes:
  main: .taskfiles/main.yml

and .taskfiles/main.yml:

version: '3'

tasks:
  default:
    - task: build
    - task: assets

  build:
    cmds:
      - go build -v -i main.go

  assets:
    cmds:
      - minify -o public/style.css src/css

I would like to run something like task main and have it automatically run task main:default

Currently though, I need to explicitly run task main:default

@tylermmorton tylermmorton added the type: bug Something not working as intended. label Jan 24, 2022
@tylermmorton
Copy link
Contributor

tylermmorton commented Jan 24, 2022

Hi @ankushg! Thank you for the report.

This does seem like the intended behavior because of the way we merge included taskfiles into the parent. I think an additional step could be added to check for the existence of default in an included taskfile and 'flatten' it, for lack of a better term. This might be a breaking change that requires a version check, though.

Just after this step:

if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil {

if(includedTaskfile.Tasks["default"] != nil) {
	t.Tasks[namespace] = includedTaskfile.Tasks["default"]
}

I'm interested in how @kerma and @andreynering feel about this. This could be a good first issue for anyone looking to contribute to the project. We would need additional unit tests to cover the behavior.

For now a good workaround could be to define task main in your Taskfile.yml:

version: '3'

includes:
  main: .taskfiles/main.yml

tasks:
  main:
    cmds:
      - task: main:default

@tylermmorton tylermmorton added type: enhancement A change to an existing feature or functionality. and removed type: bug Something not working as intended. labels Jan 24, 2022
@andreynering
Copy link
Member

Hi @ankushg,

I had the impression that this was proposed before, but I couldn't find the related issue in a quick search.

This probably makes sense, but we need to take possible conflicts into account. For example: it's possible that both a foo and a foo:default tasks exists. In this case, foo probably should be preferred instead of foo:default.

@ghostsquad
Copy link
Contributor

ghostsquad commented Apr 6, 2022

I kind of see namespaces in task as subcommands, and maybe that makes sense for how they should be treated (more or less). There's currently no enforcement of this concept though (afaik), such that you can make a task at the root called main:default that essentially "shadows" the included main:default task.

I like the concept though that namespaces are strictly enforced, and "shadowing" is either prohibited, or there's a warning that a task is shadowing an include. Allowing you to call task main which maps to the default task in the main namespace. Thusly, if you have a main namespace, also having a main task in the root Taskfile would be discouraged. (this is similar to how packages are imported in Go, and how a variable can shadow a package).

I like to look at upstream code/binaries/packages not as a way to "follow the crowd", but as a way to help "preload" intent with what a user may already be used to or expect. So how does Make handle this? (opinion: quite elegantly)

https://www.gnu.org/software/make/manual/html_node/Goals.html
https://stackoverflow.com/questions/17834582/run-make-in-each-subdirectory

@ghostsquad
Copy link
Contributor

linking this to #694 to track for v4

@andreynering
Copy link
Member

Implemented on #661.

@aweseeker
Copy link

Hi Team,

Can't we run all task defined Taskfile.yml, because if we have n number of tasks do we need to manually name each task in cmd line ''task task1 task2...'', can't we have some option like --all to run all tasks.

Thanks.

@pd93
Copy link
Member

pd93 commented Dec 15, 2022

@aweseeker see #360

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

No branches or pull requests

6 participants