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

Recent taskfile doesn't take vars from env or args #1393

Closed
titpetric opened this issue Nov 8, 2023 · 2 comments
Closed

Recent taskfile doesn't take vars from env or args #1393

titpetric opened this issue Nov 8, 2023 · 2 comments

Comments

@titpetric
Copy link

titpetric commented Nov 8, 2023

I reinstalled task today from latest:

Task version: v3.31.0 (h1:o6iyj9gPJXxvxPi/u/l8e025PmM2BqKgtLNPS2i7hV4=)

Following the docs example:

version: '3'

tasks:
  print-var:
    cmds:
      - echo "{{.VAR}}"
    vars:
      VAR: Hello!

None of the suggested methods seem to allow to override the variable value:

# VAR=foo task print-var
task: [print-var] echo "Hello!"
Hello!
# task print-var VAR=foo
task: [print-var] echo "Hello!"
Hello!
# task VAR=foo print-var
task: [print-var] echo "Hello!"
Hello!

If i move the vars definition into global scope:

# task VAR=foo print-var
task: [print-var] echo "foo"
foo
# task print-var VAR=foo
task: [print-var] echo "foo"
foo
# VAR=foo task print-var
task: [print-var] echo "Hello!"
Hello!

https://taskfile.dev/usage/#variables says overriding vars like above should be possible, and I remember the first case (explicit args per task target) working at some point, as I have taskfiles and docs in place that rely on that behaviour.

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Nov 8, 2023
@andreynering
Copy link
Member

Hi @titpetric,

As the documentation says, Variables declared in the task definition has the highest importance, so they aren't overridable by default.

Use the default template function to allow that:

version: '3'

tasks:
  print-var:
    cmds:
      - echo "{{.VAR}}"
    vars:
      VAR: '{{.VAR | default "Hello!"}}'

@andreynering andreynering closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
@andreynering andreynering added type: question Further information is requested. and removed state: needs triage Waiting to be triaged by a maintainer. labels Nov 8, 2023
@titpetric
Copy link
Author

titpetric commented Nov 8, 2023

@andreynering docs also say

$ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!"

I'm not sure what to make of it. It looks to be an example of write-file taking two args, and print taking one

Docs also explicitly state that var should be overrideable by env, and the above example shows it's not even if global

@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

4 participants