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

feat: add ALIAS special var #1764

Merged
merged 1 commit into from
Aug 25, 2024

Conversation

DanStory
Copy link
Contributor

@DanStory DanStory commented Aug 16, 2024

Adds ALIAS to special vars that represents the alias that was used when invoking the task, otherwise will be the task name.

> go run ./cmd/task --dir testdata/special_vars echo-task-alias
task: [print-task-alias] echo "echo-task-alias"
echo-task-alias

> go run ./cmd/task --dir testdata/special_vars print-task-alias
task: [print-task-alias] echo "print-task-alias"
print-task-alias

@andreynering
Copy link
Member

Hey @DanStory,

The implementation is pretty simple, so I believe we could just merge it.

That said, I'm curious on what is your use case for needing this variable. Do you mind explaining?

@andreynering andreynering added area: variables Changes related to variables. experiment: candidate Experimental feature - Pending final implementation feedback. Minor changes only. labels Aug 16, 2024
@DanStory DanStory force-pushed the feature/add-alias-var branch from 95e5091 to 9caa8ff Compare August 16, 2024 14:05
@DanStory
Copy link
Contributor Author

I'm curious on what is your use case for needing this variable. Do you mind explaining?

@andreynering, I am cleaning up and restructuring our monorepo's taskfiles while trying to prevent from breaking developers' current workflow via aliases that warn of the deprecation and executing the new task. We also have a lot of duplication of tasks for each application in the monorepo, so I am experimenting with ways to dedupe common tasks while keeping decent discoverability (task --list).

version: '3'
tasks:
## original tasks
#  old:dull:app1:
#    cmd: "..."
#  old:dull:app2:
#    cmd: "..."
#  old:dull:app3:
#    cmd: "..."

## refactor all the old:dull:x tasks for this single one
## gives feedback that is deprecated for new task format
  old:dull:
    desc: "DEPRECATED: use new:shiny -- <app>"
    vars:
      APP: '{{ternary "" (splitList ":" .ALIAS | last) (eq .ALIAS .TASK)}}'
    aliases:
      - old:dull:app1
      - old:dull:app2
      - old:dull:app3
    cmds:
      - 'echo "DEPRECATED: use new:shiny -- {{.APP}} OR new:shiny:{{.APP}}"'
      - task: 'new:shiny'
        silent: true
        vars:
          CLI_ARGS: '{{.APP}}'

## have not decided between using ALIAS vs CLI_ARGS for new structure
  new:shiny:
    desc: "the new shiny"
    vars:
      APP: '{{ternary .CLI_ARGS (splitList ":" .ALIAS | last) (eq .ALIAS .TASK)}}'
    aliases:
      - new:shiny:app1
      - new:shiny:app2
      - new:shiny:app3
    cmds:
      - echo "start {{.APP}}"
> go run ./cmd/task old:dull:app1
task: [old:dull] echo "DEPRECATED: use new:shiny -- app1 OR new:shiny:app1"
DEPRECATED: use new:shiny -- app1 OR new:shiny:app1
start app1

> go run ./cmd/task --dir ./testdata new:shiny -- app1
task: [new:shiny] echo "start app1"
start app1

> go run ./cmd/task --dir ./testdata new:shiny:app1
task: [new:shiny] echo "start app1"
start app1
> go run ./cmd/task --list
task: Available tasks for this project:
* new:shiny:       the new shiny                           (aliases: new:shiny:app1, new:shiny:app2, new:shiny:app3)
* old:dull:        DEPRECATED: use new:shiny -- <app>      (aliases: old:dull:app1, old:dull:app2, old:dull:app3)

@andreynering andreynering self-requested a review August 16, 2024 15:00
@andreynering andreynering merged commit 045d054 into go-task:main Aug 25, 2024
14 checks passed
@andreynering
Copy link
Member

@DanStory Thanks for your contribution!

andreynering added a commit that referenced this pull request Aug 25, 2024
@DanStory DanStory deleted the feature/add-alias-var branch August 26, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: variables Changes related to variables. experiment: candidate Experimental feature - Pending final implementation feedback. Minor changes only.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants