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

Variable precedence confusion #234

Closed
crewjam opened this issue Aug 8, 2019 · 2 comments
Closed

Variable precedence confusion #234

crewjam opened this issue Aug 8, 2019 · 2 comments
Labels
area: docs Changes related to documentation.

Comments

@crewjam
Copy link

crewjam commented Aug 8, 2019

Task version: 2.6.0 / darwin

The documentation states:

When doing interpolation of variables, Task will look for the below. They are listed below in order of importance (e.g. most important first):

Variables declared locally in the task
Variables given while calling a task from another. (See Calling another task above)
Variables declared in the vars: option in the Taskfile
Variables available in the Taskvars.yml file
Environment variables

So I would expect the following task file to emit "Howdy", but instead it emits "Hello"

version: '2'

tasks:
  print-greeting:
    cmds:
      - echo "{{.GREETING}}"
    vars:
      GREETING: Hello

  print-howdy:
    cmds:
      - task: print-greeting
        vars:
          GREETING: howdy
$ task print-howdy
echo "Hello"
Hello
task print-greeting
echo "Hello"
Hello

I'm not sure if this is a bug, that the docs are incorrect, or if I'm just confused.

As a side note, it seems that providing values on the command line causes a panic:

$ task GREETING=foo print-howdy
panic: assignment to entry in nil map

goroutine 1 [running]:
main.main()
	/home/travis/gopath/src/github.com/go-task/task/cmd/task/task.go:141 +0xa0b
@crewjam
Copy link
Author

crewjam commented Aug 8, 2019

So re-reading the docs, the phrase "Variables declared locally in the task" was confusing, to me anyway. Would it be more clear to say "Variables assigned in the task definition" ?

andreynering added a commit that referenced this issue Aug 10, 2019
@andreynering andreynering added type: bug Something not working as intended. area: docs Changes related to documentation. labels Aug 10, 2019
@andreynering
Copy link
Member

Hi @crewjam, thanks for opening this issue!

The panic bug was fixed here: 955359b.

About your documentation question: I understand that Task is working correctly here, and documentation is correct, but indeed it was a bit confusing. I took your suggestion here: e414c1f.

The reason the precedence is as is, is to allow the task to work with the passed value, for example having a default:

version: '2'

tasks:
 default:
   cmds:
     - echo "{{.MSG}}"
   vars:
     MSG: '{{.MSG | default "Hi!"}}'

@pd93 pd93 removed the type: bug Something not working as intended. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs Changes related to documentation.
Projects
None yet
Development

No branches or pull requests

3 participants