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

Empty string default values are not displayed #2500

Closed
m-freiberg opened this issue Apr 28, 2023 · 2 comments · Fixed by #2724
Closed

Empty string default values are not displayed #2500

m-freiberg opened this issue Apr 28, 2023 · 2 comments · Fixed by #2724
Milestone

Comments

@m-freiberg
Copy link

If an option has a default value of "", the show_default option does not display anything.

Reproducible example:

import click

@click.group()
def test_cli() -> None:
    pass 


@test_cli.command(help="Test CLI")
@click.option("--test_value", type=str, default="", show_default=True)
def test_function(
    test_value: str
) -> None:
    print(test_value)


@click.group()
def cli() -> None:
    pass


cli.add_command(test_cli)
cli()

Expected to see a default displayed. Actual behavior:
image

Environment:

  • Python version: 3.11.3
  • Click version: 8.0.3
@m-freiberg m-freiberg mentioned this issue Apr 28, 2023
6 tasks
@davidism davidism added this to the 8.2.0 milestone Jul 4, 2023
@johongo
Copy link

johongo commented Aug 10, 2023

I solved this by using the trick found under Dynamic Defaults for Prompts but I don't think the documentation mentions elsewhere that show_default can be a non-boolean value. Regardless, it still doesn't show for prompts, where the only visual signifier is the empty pair of brackets.

@stefmolin
Copy link

I'm working on this at the PyCon US 2024 sprints.

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

Successfully merging a pull request may close this issue.

4 participants