Skip to content

feat: add option to declare an included Taskfile as flatten#1704

Merged
vmaerten merged 9 commits into
go-task:mainfrom
vmaerten:feat/flatten
Aug 26, 2024
Merged

feat: add option to declare an included Taskfile as flatten#1704
vmaerten merged 9 commits into
go-task:mainfrom
vmaerten:feat/flatten

Conversation

@vmaerten

@vmaerten vmaerten commented Jul 1, 2024

Copy link
Copy Markdown
Member

It's one of the most upvoted feature ! So I gave it a try

Closes : #273

@vmaerten vmaerten marked this pull request as ready for review July 1, 2024 17:54
@vmaerten vmaerten requested review from andreynering and pd93 July 1, 2024 17:54

@ccoVeille ccoVeille left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please accept my humble code review

Comment thread .editorconfig Outdated
Comment thread task_test.go Outdated
Comment thread task_test.go Outdated
Comment thread taskfile/ast/taskfile.go Outdated
@vmaerten

vmaerten commented Jul 1, 2024

Copy link
Copy Markdown
Member Author

Thanks a lot @ccoVeille for your review. I've done all fixes in one commit

@ccoVeille

Copy link
Copy Markdown

You are welcome

@andreynering andreynering left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vmaerten, thanks for working on this!

I noticed a bug: dir: is not being respected on includes: when flatten: true is given.

version: '3'

tasks:
  pwd:
    desc: Print working directory
    cmds:
      - pwd
includes:
  included:
    taskfile: ./TaskfileIncluded.yml
    dir: ./website
    flatten: true

With flatten: true, it prints the root directory instead of the specified one (dir: ./website in my example).

Also @pd93 mentioned here (#273 (comment)) that he has refactors in mind that could affect this work. Worth getting an opinion before merging.

@vmaerten

vmaerten commented Jul 5, 2024

Copy link
Copy Markdown
Member Author

Thank @andreynering for the review. I've forgot the AdvancedImport's part
It's now fixed and work as intended. Let me know if there are some usecase I've forgotten

@vmaerten vmaerten requested a review from andreynering July 5, 2024 14:09
@elocke

elocke commented Jul 16, 2024

Copy link
Copy Markdown

Thank @andreynering for the review. I've forgot the AdvancedImport's part It's now fixed and work as intended. Let me know if there are some usecase I've forgotten

Awesome to see this feature in a PR, I've been eager to build something with this.

An usecase that I would benefit from, would be if I could specify override as an option to flatten. If set, the inheriting Taskfile's cmd would take precedence over the included files set to flatten. I could then provide sets of Task "templates" but my users could override specific cmds if they need to.

@vmaerten

Copy link
Copy Markdown
Member Author

Thank @andreynering for the review. I've forgot the AdvancedImport's part It's now fixed and work as intended. Let me know if there are some usecase I've forgotten

Awesome to see this feature in a PR, I've been eager to build something with this.

An usecase that I would benefit from, would be if I could specify override as an option to flatten. If set, the inheriting Taskfile's cmd would take precedence over the included files set to flatten. I could then provide sets of Task "templates" but my users could override specific cmds if they need to.

I agree but for now, I would keep this feature as simple as possible
We can iterate through this after ffc

@pd93 pd93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also @pd93 mentioned here (#273 (comment)) that he has refactors in mind that could affect this work. Worth getting an opinion before merging.

I have some WIP code that removes the merging altogether. This feature will need to be reworked into that at some point. However, I've not had the time to work on it recently and I don't see any reason to delay this functionality given its popularity.

The PR seems well thought out and reimplementing it if merging is removed should be simple enough.

1 minor comment, but otherwise happy. Thanks for working on this @vmaerten! 🚀

Comment thread errors/errors_task.go
}

func (err *TaskNameFlattenConflictError) Error() string {
return fmt.Sprintf(`task: Found multiple tasks (%s) included by "%s""`, err.TaskName, err.Include)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is also returned when a task in a child taskfile conflicts with one in a parent taskfile (as opposed to two children taskfiles). We could improve the message to include those cases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think about CodeTaskNameConflict or another one ?
At first I used CodeTaskNameConflict but I found more readable to distinct both. That being said, it would make sense, so I'll give a try to adjust the message

@vmaerten vmaerten changed the title feat: add flatten task feat: add option to declare an included Taskfile as flatten Aug 26, 2024
@vmaerten vmaerten merged commit ef3b853 into go-task:main Aug 26, 2024
@vmaerten vmaerten deleted the feat/flatten branch August 26, 2024 21:17
vmaerten added a commit that referenced this pull request Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to 'flatten' included taskfiles

5 participants