required=True support [typer.Option] #1588
-
First Check
Commit to Help
Example Codeimport typer
app = typer.Typer()
# currently required options look like this:
@app.command()
def main(
username: str = typer.Option(..., help="A Username")
):
<code>DescriptionPlease make typer.Option required arguments conform to a more readable syntax than ellipsis. From the function param:
unless you have working knowledge of this library you wouldn't be able to know if:
Please consider moving this feature to a kwarg in typer.Option. Wanted Solutiontyper.Option supports a new kwarg: required: bool Wanted Codeimport typer
app = typer.Typer()
# This is a more expressive and readable
@app.command()
def main(
username: str = typer.Option("", help="A Username", required=True)
):
<code>AlternativesN/A Operating SystemLinux Operating System DetailsNo response Typer Version0.4.0 Python Version3.9+ Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
IMO, the current interface is good. Adding the If anything, it should be made clearer in the instructions that to make an |
Beta Was this translation helpful? Give feedback.
-
|
check this out https://typer.tiangolo.com/tutorial/options/required/ |
Beta Was this translation helpful? Give feedback.
-
|
I just came across the same problem. I wanted to add a required Option with Choices (Enum). And i didn't want to set a default value, because i wanted that the user gets an error displayed, if he doesn't specify the option. I didn't want default value to execute silently. Hope it makes some sense. Great package btw ;) |
Beta Was this translation helpful? Give feedback.
check this out https://typer.tiangolo.com/tutorial/options/required/