Is it possible to do similar as is possible with argparse with variadic options?
parser = argparse.ArgumentParser()
parser.add_argument('--options', nargs='+')
args = parser.parse_args()
test.py --options a b c
but it seems variadic options aren't supported
@click.command('test')
@click.option('--options', nargs=-1)
def test(options):
pass
TypeError: Options cannot have nargs < 0
You need to specify multiple=True, but this will result in syntax like --options a --options b --options c.
the multiple options isn't inconvenient though.
Unfortunately this is the only way because Click wouldn't be able to tell what is an argument and what is an option (explicit is better than implicit). This is not a problem with a fixed nargs.
On 23 August 2016 16:24:25 CEST, Robbin Bonthond [email protected] wrote:
the multiple options isn't inconvenient though.
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub:
https://github.com/pallets/click/issues/641#issuecomment-241747906
Sent from my Android device with K-9 Mail. Please excuse my brevity.
If we had @click.option('--foo', greedy=True), that could indicate to the parser that no arguments follow this option, but arguments can follow the next non-greedy option. This might also be a place to consider adding the -- token to signal the end of a greedy list.
Most helpful comment
If we had
@click.option('--foo', greedy=True), that could indicate to the parser that no arguments follow this option, but arguments can follow the next non-greedy option. This might also be a place to consider adding the--token to signal the end of a greedy list.