You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There have been several requests (#889, #714, #495) for a way to enforce or check that variables are set before running a task. There have been several solutions proposed, but most of them require some fairly obscure use of template functions, bash tricks, or are a little verbose/clumsy.
Being able to define what vars are required before running a task is pretty important IMO, esp for developer experience. It prevents that "oh shoot I forgot that one var in my .env file" problem, guides people towards the answer, rather than letting some command or script depending on that variable fail in cryptic & possibly dangerous ways. Sometimes when running a deployment or release a missing variable might not be obvious until a significant time has elapsed.
Proposal
A new field called requires is added to the task struct, this field is an array of strings. These strings should be variable names, and these variables are checked for existence before the task is run. If one or more is found to be missing, the task will not run and an error describing the missing variable(s) is returned.
Simple example
version: '3'tasks:
docker-build:
cmds:
- 'docker build . -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}}'# Make sure these variables are set before runningrequires: [IMAGE_NAME, IMAGE_TAG]
For discussion:
Is requires a good name? It's short and elegant, but maybe implies some other dependency? I considered requiredVars but the camel case made me cringe a bit.
I considered the idea of allowing users to specify the message in a failed check, but this significantly distracts from the elegance of a simple array of strings
I believe this important enough to be a "1st class" feature of task, so I shall be submitting a PR shortly to implement this feature
The text was updated successfully, but these errors were encountered:
There have been several requests (#889, #714, #495) for a way to enforce or check that variables are set before running a task. There have been several solutions proposed, but most of them require some fairly obscure use of template functions, bash tricks, or are a little verbose/clumsy.
Being able to define what vars are required before running a task is pretty important IMO, esp for developer experience. It prevents that "oh shoot I forgot that one var in my .env file" problem, guides people towards the answer, rather than letting some command or script depending on that variable fail in cryptic & possibly dangerous ways. Sometimes when running a deployment or release a missing variable might not be obvious until a significant time has elapsed.
Proposal
A new field called
requires
is added to thetask
struct, this field is an array of strings. These strings should be variable names, and these variables are checked for existence before the task is run. If one or more is found to be missing, the task will not run and an error describing the missing variable(s) is returned.Simple example
For discussion:
requires
a good name? It's short and elegant, but maybe implies some other dependency? I consideredrequiredVars
but the camel case made me cringe a bit.I believe this important enough to be a "1st class" feature of
task
, so I shall be submitting a PR shortly to implement this featureThe text was updated successfully, but these errors were encountered: