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

Vars passed from the CLI don't seem to work #1759

Closed
Thiht opened this issue Aug 14, 2024 · 3 comments
Closed

Vars passed from the CLI don't seem to work #1759

Thiht opened this issue Aug 14, 2024 · 3 comments

Comments

@Thiht
Copy link

Thiht commented Aug 14, 2024

I want to override a task variable from the CLI following this documentation: https://taskfile.dev/usage/#variables and I can't make it work

I'm assuming I'm doing something wrong but I can't figure it out so I guess it's a bug?

Here's an example:

version: "3"
tasks:
  example:
    vars:
      FILE: "*.yml"
    cmds:
      - "echo '{{.FILE}}'"
$ task example
task: [example] echo '*.yml'
*.yml

$ task example FILE=foo
task: [example] echo '*.yml'
*.yml

$ FILE=foo task example
task: [example] echo '*.yml'
*.yml
  • Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=)
  • Operating system: macOS Sonoma 14.6.1
  • Experiments enabled: no
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Aug 14, 2024
@vmaerten
Copy link
Member

Hello
You need to use the default function (https://taskfile.dev/next/reference/templating/#default-functions) as follow :

version: "3"
tasks:
  example:
    vars:
      FILE: '{{.FILE | default "*.yml"}}'
    cmds:
      - "echo '{{.FILE}}'"

@task-bot task-bot removed the state: needs triage Waiting to be triaged by a maintainer. label Aug 14, 2024
@andreynering andreynering added the type: question Further information is requested. label Aug 14, 2024
@Thiht
Copy link
Author

Thiht commented Aug 14, 2024

Thanks, this solves my issue!

May I ask why what I did doesn't work, and if there are plans to make it work? Using a default is very non-intuitive. I couldn't find the solution anywhere online, and there's zero chance I would have thought of using default.

At the very least it would be great if you could update the docs I linked on variables because in its current state it's just not working.

@vmaerten
Copy link
Member

Actually it's written in the docs :

image

More important first, the first one being Variables declared in the task definition (which is your case), so it won't look for Environment variables (last one)

There is no plan to make it work because it would be a breaking changes (at least not before the next major which is not planned at all).

But you're right, we need to show this use case in the doc. I'll update the doc with an example using default

@pd93 pd93 removed the type: question Further information is requested. label Dec 15, 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

No branches or pull requests

5 participants