You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

class-argparse

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-argparse

Class based argument parser

0.1.3
pipPyPI
Maintainers
1

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

  • The class ClassArgParser extends ArgumentParser
  • The initialization function finds add adds all the methods on child classes that are public i.e. their names don't start with __
  • 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

Keywords

Class Based

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts