click-contrib / click-repl

Subcommand REPL for click apps
MIT License
215 stars 41 forks source link

List of options does not show in some cases #107

Open tmahmood opened 11 months ago

tmahmood commented 11 months ago

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()