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

from class_argparse import ClassArgParser


class Main(ClassArgParser):
    """
    # ClassArgParser
    example description
    """

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

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

    def no_args_with_desc(self):
        """
        some desc text goes here
        second line of desc
        """
        print("no_args_with_desc")

    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.4.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

class_argparse-0.1.4-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file class_argparse-0.1.4.tar.gz.

File metadata

  • Download URL: class_argparse-0.1.4.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for class_argparse-0.1.4.tar.gz
Algorithm Hash digest
SHA256 714a99880b188133e1023d78e5a95e4b6391b1d9253a179f0e4c94c4fa82610a
MD5 0b11a86905c6e4a20ed17f1fa2c766a7
BLAKE2b-256 f847c0ee0960f0172a6830da300a818921ea59d41ccab8507539c0a54a617fe2

See more details on using hashes here.

Provenance

The following attestation bundles were made for class_argparse-0.1.4.tar.gz:

Publisher: release.yml on neblar/class-argparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: class_argparse-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for class_argparse-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ed89b63fbf761f6ef8d8c77b00c2705b1457c6044946cc676d766f3995253a65
MD5 597ee94cf7b68243d65f1e83a341449d
BLAKE2b-256 532c1ebeeeb8f2a6da1889d1c2dae87c10b66dc4e3ae6622dd8b672eda0498d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for class_argparse-0.1.4-py3-none-any.whl:

Publisher: release.yml on neblar/class-argparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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