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

Allow overriding the task name in the logger output #321

Closed
adamwasila opened this issue May 7, 2020 · 3 comments · Fixed by #337
Closed

Allow overriding the task name in the logger output #321

adamwasila opened this issue May 7, 2020 · 3 comments · Fixed by #337
Labels
type: feature A new feature or functionality.

Comments

@adamwasila
Copy link
Contributor

Given example Taskfile:

version: '2'

tasks:
  a:
    cmds:
      - task: b
      - task: b
      - task: b

  b:
    cmds:
      - echo "Hello b"
    sources:
      - "source.txt"

Then if source.txt is present I see following output:

task a
task: Task "b" is up to date
task: Task "b" is up to date
task: Task "b" is up to date

Now, the problem is that I cannot customize this output to parametrize task name for each execution separately. This makes output quite unclear of what has actually happened and it could be easily solved using following syntax:

tasks:
  a:
    cmds:
      - task: b
        alias: firstb
      - task: b
        alias: secondb
      - task: b
        alias: thirdb

task a
task: Task "firstb" is up to date
task: Task "secondb" is up to date
task: Task "thirdb" is up to date

Now, the real use case is I have kind of "template" task to build single go binary which I don't want to repeat for every command for obvious reasons (DRY):

  build_target:
    cmds:
      - "go build {{.BUILD_FLAGS}} -o {{.PREFIX}}{{.TARGET}} ./cmd/{{.TARGET}}"
    sources:
      - "**/*.go"
    generates:
      - "{{.PREFIX}}{{.TARGET}}"

Now, project has multiple commands to build, but all I see is:

task build
task: Task "build_target" is up to date
task: Task "build_target" is up to date
task: Task "build_target" is up to date

instead of desired:

task build
task: Task "cmd/command1" is up to date
task: Task "cmd/othercommand" is up to date
task: Task "cmd/supercommand" is up to date
@andreynering andreynering added the type: feature A new feature or functionality. label May 9, 2020
@andreynering andreynering changed the title It should be possible to override name of called task Allow overriding the task name in the logger output May 9, 2020
@andreynering
Copy link
Member

andreynering commented May 9, 2020

Hi @adamwasila,

Sounds like a reasonable feature request

@adamwasila
Copy link
Contributor Author

I made a quick hack to check how it could work. You may see it in this branch: https://github.com/adamwasila/task/tree/subtask-alias
What do you think about it? Should I add support for tasks called by deps and send you pull request or should I rewrite/refactor it first?

Example Taskfile.yml to test against my branch:

version: '2'

tasks:
  default:
    deps:
      - test
    cmds:
      - task: test
        alias: "foo"
      - task: test
        alias: "bar"
      - task: test
  test:
    desc: lorem ipsum
    cmds:
      - echo "hello world"
    sources:
      - Taskfile.yml
    generates:
      - Taskfile.yml

@andreynering
Copy link
Member

@adamwasila Sounds like a good way to implement it

Just remember to use v3 as your base branch instead of master

Also, I'm not sure alias is the right name for this, but I don't have a better name in my mind at the moment

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
Development

Successfully merging a pull request may close this issue.

2 participants