Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of options does not show in some cases #107

Open
tmahmood opened this issue Jul 25, 2023 · 0 comments
Open

List of options does not show in some cases #107

tmahmood opened this issue Jul 25, 2023 · 0 comments

Comments

@tmahmood
Copy link

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant