How create an option with an optional argument (e.g. a flag with an optional value) #608
Unanswered
taranlu-houzz
asked this question in
Questions
Replies: 1 comment
-
some hints? how to do this? @app.command()
def test_flag(flag: Optional[str] = typer.Option(None, is_flag=False, flag_value='default')):
if flag is not None:
print(f"{flag=}")
else:
print("flag unset") calling
what is the purpose of parameter |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
In
click
, it is possible to create an option with an optional value: https://click.palletsprojects.com/en/8.1.x/options/#optional-valueI'm wondering if it is possible to do this in
typer
?For the example given above, I would expect the following:
--opt-1
flag passed:None
--opt-1
flag is passed with no value:3.14
(default value)--opt-1
flag is passed with a value (99
):99
(value that was passed)Operating System
macOS
Operating System Details
No response
Typer Version
0.9.0
Python Version
3.10.10
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions