click-repl icon indicating copy to clipboard operation
click-repl copied to clipboard

List of options does not show in some cases

Open tmahmood opened this issue 1 year ago • 0 comments

When I have an option with Choice, the choices are not displayed. It displays true/false listing.

Here after typing -a/--add it should show

> print-opt -a
                foo    
                bar    

instead it displays:

> print-opt -a
                true   1/true/t/yes/y/on   
                false  0/false/f/no/n/off  

Interestingly, if I rearrange the parameters, and put the option with Choice at the end, it will display the list of available option correctly.

The following code reproduces the issue.

import click
import click_repl

A_LIST = ["foo", "bar"]


@click.group()
@click.pass_context
def root_command(ctx):
    pass


@root_command.command()
@click.pass_context
def shell(
        ctx: click.core.Context,
) -> None:
    """Starts a interactive terminal"""
    click_repl.repl(ctx)


# Following code will not display the list of available options but, if I rearrange the code like this
#       @click.option("-v", "--view", is_flag=True, default=False, help="View search sources")
#       @click.option("-a", "--add", type=click.Choice(A_LIST, case_sensitive=False))
# It will display the list of available option
@root_command.command()
@click.option("-a", "--add", type=click.Choice(A_LIST, case_sensitive=False))
@click.option("-v", "--view", is_flag=True, default=False, help="View search sources")
@click.pass_context
def print_opt(ctx, add, view):
    print(add)


if __name__ == '__main__':
    root_command()

tmahmood avatar Jul 25 '23 07:07 tmahmood