Skip to content

Multiple options mixing #2297

Answered by jwodder
pyhedgehog asked this question in Q&A
Discussion options

You must be logged in to vote

This issue may be relevant: #1730. The code I eventually ended up going with in that case looks like:

from   collections import namedtuple
import click

Apple = namedtuple('Apple', 'value')
Banana = namedtuple('Banana', 'value')
Coconut = namedtuple('Coconut', 'value')

def set_option(ctx, param, value):
    if value is not None:
        ctx.params["option"] = value
    return value

@click.command()
@click.option('-a', '--apple', type=Apple, callback=set_option, expose_value=False)
@click.option('-b', '--banana', type=Banana, callback=set_option, expose_value=False)
@click.option('-c', '--coconut', type=Coconut, callback=set_option, expose_value=False)
def main(option=None):
    click.echo(

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pyhedgehog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2296 on May 27, 2022 02:28.