Skip to main content

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

declarative_argparse-0.0.7.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

declarative_argparse-0.0.7-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page