click icon indicating copy to clipboard operation
click copied to clipboard

Empty string default values are not displayed

Open m-freiberg opened this issue 2 years ago • 1 comments

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 avatar Apr 28 '23 18:04 m-freiberg

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.

johongo avatar Aug 10 '23 15:08 johongo

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

stefmolin avatar May 20 '24 15:05 stefmolin