[Python] typer.Option in python

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have a typer cli command like this:

    @app.command(
    no_args_is_help=True,
    help="Test command help text"
    )
    def test(name:str = typer.Option(
    None,
    "--test",
    "-t",
    help="help text"
    )):
    print(name)


    How can I make this flags --test or -t optional? for example if i just write command python3 code.py test -t, I want it to print "all" or something default. Is there a way to make this flag arguments optional?

    I tried

    if test is None:
    test = "all"


    also I tried to make default value "all" instead of None but still not working. I always get this error: Option [flag name] requires an argument

    Continue reading...

Compartilhe esta Página