https://github.com/mamoruds/typed-cap
A python Command-line Argument Parser that provides typing support.
https://github.com/mamoruds/typed-cap
argparser command-line-parser python3
Last synced: about 1 year ago
JSON representation
A python Command-line Argument Parser that provides typing support.
- Host: GitHub
- URL: https://github.com/mamoruds/typed-cap
- Owner: MamoruDS
- License: mit
- Created: 2021-09-23T13:00:29.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-17T07:36:17.000Z (over 2 years ago)
- Last Synced: 2025-05-07T06:04:00.807Z (about 1 year ago)
- Topics: argparser, command-line-parser, python3
- Language: Python
- Homepage:
- Size: 687 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# typed-cap
[](https://pypi.org/project/typed-cap/)
[](https://github.com/psf/black)
Cap is a python **C**ommand-line **A**rgument **P**arser that provides **typing** support. Using Cap requires less code to generate a more easy to use parser.
## Usage
⚠️ `typed_cap` required `python>=3.9`
```
pip install typed_cap
```
### Quick Example
```python
from typed_cap import Cap
class Args:
"""description here"""
# @alias=c
config: str | None
"""file path to config file"""
# @alias=d
depth: int
"""depth of search"""
dry_run: bool = True
"""run without making any changes"""
cap = Cap(Args)
parsed = cap.parse()
print(parsed.args.__dict__)
print(parsed.argv)
```
```shell
python demo.py
# Cap.parse: option depth:int is required but it is missing
# ArgsParserMissingArgument
python demo.py --help
# description here
#
# OPTIONS:
# -c,--config file path to config file
# -d,--depth depth of search
# --dry_run run without making any changes (default: True)
# -h,--help display the help text
python demo.py -d 5 hello typed cap
# {'depth': 5, 'config': None, 'dry_run': True}
# ['hello', 'typed', 'cap']
```