T
Task3w ago
Nargit

Requires vars and CLI_ARGS cohabitation ?

I would like to simplify the usage of task and vars when using the cli
tasks:
default:
requires:
vars:
- MY_ARG
vars:
MY_ARG : '{{ index (splitArgs .CLI_ARGS) 0 }}'
cmds:
- echo "Hello {{ .MY_ARG }}"
tasks:
default:
requires:
vars:
- MY_ARG
vars:
MY_ARG : '{{ index (splitArgs .CLI_ARGS) 0 }}'
cmds:
- echo "Hello {{ .MY_ARG }}"
task # no args will trigger an errors
task # no args will trigger an errors
task -- foo # will work
task -- foo # will work
When calling task without args, requires is not triggerd. Without the fallback to empty string, I get an error with index out of range: 0 which make requires totaly useless. I know CLI_ARGS is not used to manage task variables and instead I should use task MY_ARG=my_value but i believe task is very close to be used as a regular CLI.
2 Replies
andreynering
andreynering3w ago
Hi @Nargit. You may be interested in https://github.com/go-task/task/issues/2139
GitHub
Split CLI args experiment · Issue #2139 · go-task/task
Description When the CLI_ARGS variable was first introduced, Task only had string variables, so the variable was populated with a single string with shell quoted values. Since then we have introduc...
Nargit
NargitOP3w ago
not sure how this could help

Did you find this page helpful?