Skip to main content

Class based argument parser

Project description

Class-Argparse

Class based argument parser to simplify writing CLIs that have lots of options

How to use

from typing import Literal

class Main(ClassArgParser):

    def __init__(self) -> None:
        super().__init__(name="Class ArgParser")

    def no_args(self):
        print("no_args")

    def some_args(self, arg: str):
        print("some_args", arg)

    def default_values(self, arg: str, default: int = 0):
        print("default_values", arg, default)

    def list_values(self, values: List[str]):
        print("list_values", values)

    def untyped_arg(self, untyped):
        print("untyped_arg", untyped)

    async def async_func(self, arg: str):
        print("async_func", arg)

    def literal_options(self, arg: Literal["a", "b"]):
        print("literal_options", arg)

if __name__ == "__main__":
    Main()()

How this works

  1. The class ClassArgParser extends ArgumentParser
  2. The initialization function finds add adds all the methods on child classes that are public i.e. their names don't start with __
  3. The object of the class is called and after identifying whether the function being called it is async or sync it runs the function accordingly

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

class-argparse-0.1.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

class_argparse-0.1.3-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file class-argparse-0.1.3.tar.gz.

File metadata

  • Download URL: class-argparse-0.1.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for class-argparse-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c51643f6e961177f5e9e010cf4ea0aeaa297b754751ef7681bf3cf1a0860c76d
MD5 1aeb23a50820cdd7026ecbe5f30253bb
BLAKE2b-256 6005b935fe18823f39f38c8c76b796e6281adf16aea213aff071c40a7deba274

See more details on using hashes here.

File details

Details for the file class_argparse-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for class_argparse-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 63c103fe7929be30878467b5e4903128297b63a5fc5bc6d6ecbc2b3b56b465c0
MD5 1714922fe8d14dba2c6ce7669c9e8870
BLAKE2b-256 7ae7fe33a9a9c3f184ccc8901d432380744c8c1d6ea8d2b0d2472314ed57e021

See more details on using hashes here.

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