[Python] Click help text shows 'dynamic' when an option has the default set to a lambda

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have this code in a CLI:

    @click.option(
    "--username",
    default=lambda: os.environ.get("USER", None),
    show_default=True,
    help="User name for SSH configuration.",
    )


    When I invoke the CLI with --help option, I get this:

    --username TEXT User name for SSH configuration. [default:
    (dynamic)]


    Is there a way to make click invoke the lambda function and show the actual username instead of (dynamic)? I know I can call that function before invoking the click decorator and pass that retrieved value as the default instead of lambda. I am trying to do better than that.

    Continue reading...

Compartilhe esta Página