Skip to content

Commit 2574633

Browse files
v67
1 parent bfcaec1 commit 2574633

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@ Argument parser based on pydantic v2.
88
pip install pydantic-argparse-next
99
```
1010

11+
### Base usage:
12+
13+
#
14+
15+
```python
16+
from pydantic import BaseModel, Field
17+
import pydantic_argparse_next as pa
18+
19+
20+
class Temp(BaseModel):
21+
# Positional arguments
22+
a: str = pa.Arg(description="This is a required positional argument.")
23+
b: str = pa.Arg("defalut_value", description="This is a OPTIONAL positional argument.")
24+
25+
# Keyword arguments
26+
# Simple attributes or pydantic.Field are keyword arguments.
27+
c: str
28+
d: str = Field(None, description="This is a OPTIONAL keyword argument.")
29+
e: str = pa.KwArg(description="This is a required keyword argument.")
30+
```
31+
32+
```
33+
Input: appname "test1" --c "test2" --e="test3"
34+
Output: a='test1' b='defalut_value' c='test2' d=None e='test3'
35+
```
36+
37+
**More details in the documentation**
38+
1139
### Supports:
1240

1341
✅ Positional arguments
@@ -46,6 +74,8 @@ pip install pydantic-argparse-next
4674

4775
        ⬜ Easy load config from file
4876

77+
**More details in the documentation**
78+
4979
### Docs and examples:
5080

5181
1. [Base usage](https://github.com/overgodofchaos/pydantic-argparse-next/blob/main/docs/BaseUsage.md)

examples/Base/example_0.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from pydantic import BaseModel, Field
2+
import pydantic_argparse_next as pa
3+
4+
5+
class Temp(BaseModel):
6+
# Positional arguments
7+
a: str = pa.Arg(description="This is a required positional argument.")
8+
b: str = pa.Arg("defalut_value", description="This is a OPTIONAL positional argument.")
9+
10+
# Keyword arguments
11+
# Simple attributes or pydantic.Field are keyword arguments.
12+
c: str
13+
d: str = Field(None, description="This is a OPTIONAL keyword argument.")
14+
e: str = pa.KwArg(description="This is a required keyword argument.")
15+
16+
17+
cliargs = pa.parse(Temp, program_name="Example program", description="The example program description")
18+
19+
print(cliargs)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[project]
66
name = "pydantic-argparse-next"
7-
version = "1.0.4"
7+
version = "1.0.5"
88
description = "Pydantic 2 argparse."
99
readme = "README.md"
1010
requires-python = ">=3.11"

0 commit comments

Comments
 (0)