As far as I have seen no, the pre and post conditions are created at "compile time", which means they won't have access to a parameter. Alternatively, it is part from perfect,
but you can use the fact that you can call one task from another (it is not explained in the docs) to manually do your pretask condition.
from invoke import Collection, task
@task
def hello(c):
print("hello")
@task
def goodbye(c, a=False):
if a:
col = Collection()
col.add_task(hello)
col['hello'](c)
print('goodbye')
Outputs
> invoke goodbye
goodbye
> invoke goodbye -a
hello
goodbye
It does feel "hacky", but as far as I can this is the easier way.
Note:
If for any reason your tasks are already part of a namespace
or ns
variable,
you don't need to create a new collection, just call them from the namespace itself as in
namespace['hello'](c)