Suppose we have the following function, which
has an optional parameter exclude
, which is expected
to be a list of strings:
@group.command()
@click.option(???)
def load(exclude = None):
# ...
I want the user to be able to execute the script like so:
python script.py load --exclude one two three
or
python script.py load --exclude something
In which case, I would expect exclude
to be
['one', 'two', 'three']
and ['something']
, respectively.
But I want the number of values in --exclude
to be variable, including 0. I.e. The user should be able to execute
python script.py load
In which case exclude
should be None
(or []
, does not matter).
How can I do that using click?
My only viable option so far is forcing the user to use
python script.py load --exclude "one two three"
and then calling exclude.split()
, but something cleaner would be better.