Search code examples
taskfile

Go-task (taskfile) pass variables from command line


I create a few jobs using Go-Task but I don't find any reference in the API docs of how to pass variables as command line arguments.

Currently I use .CLI_ARGS to pass a sequence of numbers which I use in my jobs, but I want to pass from the command line also something like: CERT_PATH and CERT_KEY.

I thought something like:

task MyTaskName vars=CERT_PATH:value;CERT_KEY:value -- ARG1 ARG2 ARG3

Is this possible?


Solution

  • Just use a syntax similar to shell/make to pass variable after task name:

    task MyTaskName CERT_PATH=value CERT_KEY=value -- ARG1 ARG2 ARG3
    

    From https://taskfile.dev/usage/#variables:

    Since some shells do not support the above syntax to set environment variables (Windows) tasks also accept a similar style when not at the beginning of the command.

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