A simple wrapper around argparse to permit declarative construction and argument retrieval.
Project description
Declarative Argparse
This project introduces a wrapper argound the built-in argparse
module that permits one to make a declarative parser for options.
[[TOC]]
Example
import argparse
from declarative_argparse import DeclarativeOptionParser
from declarative_argparse.options.int import IntDO
from declarative_argparse.options.str import StrDO
class DAPExample(DeclarativeOptionParser):
def __init__(self) -> None:
super().__init__(argp=argparse.ArgumentParser())
self.x: IntDO = self.addInt('--x', '-x', description='X coordinate')
self.y: IntDO = self.addInt('--y', '-y', description='Y coordinate')
self.name: StrDO = self.addStr('--name', description='Change tile name').setNArgs('?')
self.id: StrDO = self.addStr('id', description='specify tile ID')
# ...
args = DAPExample()
args.parseArguments(['--x=0', '-y', '1', 'abc1'])
assert args.x.get_value() == 0
assert args.y.get_value() == 1
assert args.name.get_value() is None
assert args.id.get_value() == 'abc1'
License
MIT
Contributions are always welcome.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file declarative_argparse-0.0.8.tar.gz
.
File metadata
- Download URL: declarative_argparse-0.0.8.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5deb1f0f47ab38a0dbccb65ef9c941a0da63035c2e335444d4df988445a9b238 |
|
MD5 | b3a65650f43971444e2ac4cd9710a925 |
|
BLAKE2b-256 | 936d3b1cc14ee28a586b32f3a7d75f03bda051bb89d89c6d20867fc1bc8edddb |
File details
Details for the file declarative_argparse-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: declarative_argparse-0.0.8-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 419bacfb59035b9ee05f50928598fed435951c35b7fa7b664f4c70e3cab5c57b |
|
MD5 | d5b770400fda2c7584aa6bcc0e88eb49 |
|
BLAKE2b-256 | 65684163b855834555900efb877ef6874b10165240367a9bd49268ea23a630c7 |