edornd / argdantic

Typed command line interfaces with argparse and pydantic
MIT License
38 stars 4 forks source link

Add custom Field function #10

Closed edornd closed 1 year ago

edornd commented 1 year ago

The pydantic Field already provides the means to extend with additional arguments. This can be exploited to provide optional names, help and so on. However, names and positions of such arguments are not optimal. Evolve this:

class Config(BaseModel):
    foo: str = Field(..., description="A foo", names=("--bar", "-f"))

into this:

class Config(BaseModel):
    foo: str = ArgField("--bar", "-f", default=None, description="A foo")

It's not much, but it follows argparse style a little more.