Closed pablospe closed 2 months ago
Currently, you have to annotate the fields with typer.Option
in addition to pydantic.Field
to add a custom cli help text like so:
from typing import Annotated
import pydantic_typer
from pydantic import BaseModel, Field
from typer import Option
class User(BaseModel):
id: Annotated[int, Option(help="The unique identifier for the user")] = Field(
..., description="The unique identifier for the user"
)
name: Annotated[str, Option(help="The name of the user")] = Field(
"John Doe", description="The name of the user"
)
def main(user: User):
print(user, type(user))
if __name__ == "__main__":
pydantic_typer.run(main)
It would probably make sense to copy all metadata of the Field
into the typer.Option
automatically. I started working on this in a PR.
How to see the help
description
when doing--help
?