Kakha Chankseliani
Kakha Chankseliani

Reputation: 1

typer.Option in python

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

Upvotes: 0

Views: 26

Answers (0)

Related Questions