Skip to content

Commit

Permalink
Add custom aliases to simple example and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SupImDos committed Feb 9, 2025
1 parent 0a617db commit 8ae25f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import pydantic_argparse

class Arguments(pydantic.BaseModel):
# Required Args
string: str = pydantic.Field(description="a required string")
integer: int = pydantic.Field(description="a required integer")
flag: bool = pydantic.Field(description="a required flag")
string: str = pydantic.Field(description="a required string", aliases=["-s"])
integer: int = pydantic.Field(description="a required integer", aliases=["-i"])
flag: bool = pydantic.Field(description="a required flag", aliases=["-f"])

# Optional Args
second_flag: bool = pydantic.Field(False, description="an optional flag")
Expand Down Expand Up @@ -69,29 +69,32 @@ if __name__ == "__main__":

```console
$ python3 example.py --help
usage: Example Program [-h] [-v] --string STRING --integer INTEGER --flag |
--no-flag [--second-flag] [--no-third-flag]
usage: Example Program [-h] [-v] [-s STRING] [-i INTEGER] [-f | --flag | --no-flag]
[--second-flag] [--no-third-flag]

Example Description

required arguments:
--string STRING a required string
--integer INTEGER a required integer
--flag, --no-flag a required flag
-s STRING, --string STRING
a required string
-i INTEGER, --integer INTEGER
a required integer
-f, --flag, --no-flag
a required flag

optional arguments:
--second-flag an optional flag (default: False)
--no-third-flag an optional flag (default: True)
--second-flag an optional flag (default: False)
--no-third-flag an optional flag (default: True)

help:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-h, --help show this help message and exit
-v, --version show program's version number and exit

Example Epilog
```

```console
$ python3 example.py --string hello --integer 42 --flag
$ python3 example.py --string hello -i 42 -f
string='hello' integer=42 flag=True second_flag=False third_flag=True
```

Expand Down
23 changes: 13 additions & 10 deletions docs/examples/simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,32 @@
### Check Help
```console
$ python3 simple.py --help
usage: Example Program [-h] [-v] --string STRING --integer INTEGER --flag |
--no-flag [--second-flag] [--no-third-flag]
usage: Example Program [-h] [-v] [-s STRING] [-i INTEGER] [-f | --flag | --no-flag]
[--second-flag] [--no-third-flag]

Example Description

required arguments:
--string STRING a required string
--integer INTEGER a required integer
--flag, --no-flag a required flag
-s STRING, --string STRING
a required string
-i INTEGER, --integer INTEGER
a required integer
-f, --flag, --no-flag
a required flag

optional arguments:
--second-flag an optional flag (default: False)
--no-third-flag an optional flag (default: True)
--second-flag an optional flag (default: False)
--no-third-flag an optional flag (default: True)

help:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-h, --help show this help message and exit
-v, --version show program's version number and exit

Example Epilog
```

### Parse Arguments
```console
$ python3 simple.py --string hello --integer 42 --flag
$ python3 simple.py --string hello -i 42 -f
string='hello' integer=42 flag=True second_flag=False third_flag=True
```
6 changes: 3 additions & 3 deletions examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Arguments(pydantic.BaseModel):
"""Simple Command-Line Arguments."""

# Required Args
string: str = pydantic.Field(description="a required string")
integer: int = pydantic.Field(description="a required integer")
flag: bool = pydantic.Field(description="a required flag")
string: str = pydantic.Field(description="a required string", aliases=["-s"])
integer: int = pydantic.Field(description="a required integer", aliases=["-i"])
flag: bool = pydantic.Field(description="a required flag", aliases=["-f"])

# Optional Args
second_flag: bool = pydantic.Field(False, description="an optional flag")
Expand Down

0 comments on commit 8ae25f4

Please sign in to comment.