pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.38k stars 367 forks source link

Suggestion: mutually exclusive arguments #847

Open jamiet-msm opened 2 years ago

jamiet-msm commented 2 years ago

Hi, I am currently writing an invoke task that will carry out some operation on a group of users. For reasons I won't go into we have multiple ways of specifying users so my task looks something like this:

@task(
    iterable=["consent_id", "account_id", "email_address"]
)
def do_thing(ctx, consent_id, account_id, email_address):
  # logic to check that the caller has specified either some `consent_id`s, `account_id`s or `email_address`es, but not
  # a combination thereof. The caller should specify either `consent_id`s OR `account_id`s OR `email_address`es.

it would be handy if invoke had a way to do this on my behalf. i.e. specify arguments that are mutually exclusive. Perhaps like so:

@task(
    iterable=["consent_id", "account_id", "email_address"],
    mutually_exclusive=[[consent_id, account_id, email_address], [<other mutually exclusive args>]]
)
def do_thing(ctx, consent_id, account_id, email_address):

hope that makes sense. Consider it a feature request.

grumBit commented 1 year ago

Hi @jamiet-msm , how did you get on with this? I have a similar requirement.