clean up and refactor
This commit is contained in:
parent
cb95da6407
commit
22b7eaf593
16 changed files with 136 additions and 500 deletions
28
examples/models.py
Normal file
28
examples/models.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Alpha(BaseModel):
|
||||
a: int
|
||||
|
||||
|
||||
class Color(BaseModel):
|
||||
r: int
|
||||
g: int
|
||||
b: int
|
||||
alpha: Alpha
|
||||
|
||||
|
||||
class Hair(BaseModel):
|
||||
color: Color
|
||||
length: int
|
||||
|
||||
|
||||
class Person(BaseModel):
|
||||
name: str
|
||||
other_name: Optional[str] = None
|
||||
age: int
|
||||
email: Optional[str]
|
||||
pet: str = "dog"
|
||||
address: str = Field("123 Main St", description="Where the person calls home.")
|
||||
hair: Hair
|
||||
13
examples/person.py
Normal file
13
examples/person.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
from examples.models import Person
|
||||
from pydantic_typer import expand_pydantic_args
|
||||
|
||||
|
||||
@expand_pydantic_args()
|
||||
def get_person(person: Person, thing: str = None) -> Person:
|
||||
"""mydocstring"""
|
||||
from rich import print
|
||||
|
||||
print(str(thing))
|
||||
|
||||
print(person)
|
||||
30
examples/person_cli.py
Normal file
30
examples/person_cli.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import typer
|
||||
|
||||
from examples.models import Person
|
||||
from pydantic_typer import expand_pydantic_args
|
||||
|
||||
app = typer.Typer(
|
||||
name="pydantic_typer",
|
||||
help="a demo app",
|
||||
)
|
||||
|
||||
|
||||
@app.callback()
|
||||
def main() -> None:
|
||||
return
|
||||
|
||||
|
||||
@app.command()
|
||||
@expand_pydantic_args(typer=True)
|
||||
def get_person(person: Person, thing: str, another: str = "this") -> Person:
|
||||
"""Get a person's information."""
|
||||
from rich import print
|
||||
|
||||
print(thing)
|
||||
print(another)
|
||||
|
||||
print(person)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
typer.run(get_person)
|
||||
Loading…
Add table
Add a link
Reference in a new issue