import argtyper from typing import Tuple def type_test( pos_arg: Tuple[int, float], opt_arg: Tuple[str, int, str] = ("Nr.", 1, "Tester"), ): print(f"Positional Arg: {pos_arg}") print(f"Optional Arg: {opt_arg}") at = argtyper.ArgTyper(type_test) at()
import argtyper class Test: def __init__(self, value): self.value = value def test_message(self, message: str): print(message) print(self.value) def get_value(self): print(self.value) @argtyper.SubCommand(get_value) @argtyper.SubCommand("test_message") def entry( self, ): ... t = Test("---- Instance Value ----") at = argtyper.ArgTyper(t.entry) at()
import argtyper def hello(name: str, amount: int = 2): print("\n".join([f"Hello {name.upper()}"] * amount)) at = argtyper.ArgTyper(hello) parser = at.get_parser() parser.add_argument('--myversion', action='version', version="Super %(prog)s 1.3.3.7") at()
import argtyper def footer1(footer: str, hide: bool = False): if not hide: print(f"-- {footer}") async def footer2(footer: str, repeat: int = 2): print(f"{footer}" * repeat) # Hint: The ordering of decorators is irrelevant @argtyper.SubParser( title="Subcommands", description="The additional commands to append", help="We can run this", ) # Subcommands are `registered` at the parent @argtyper.SubCommand(footer1, name="footer_main") @argtyper.SubCommand(footer2) def hello(name: str, amount: int = 5): print(f"Hello {name.upper()}\n" * amount) at = argtyper.ArgTyper(hello, arg_defaults={"amount": 2}) at()
import re import argtyper argtyper.Argument("pattern", help="The pattern to search for")(re.search) argtyper.Argument( "string", help="The string, in which you want to search for the pattern")(re.search) at = argtyper.ArgTyper(re.search) responses = at(return_responses=True) print(responses[0])
import argtyper import argparse async def sub1(signature: str, hide: bool = False): if not hide: print(f"-- {signature}") @argtyper.Command(parents=[argtyper.ArgTyper(sub1).get_parser()], add_help=False) async def sub2(footer: str, debug: bool = False, show: argparse.BooleanOptionalAction = True): print(footer, debug, show) @argtyper.Command(parents=[argtyper.ArgTyper(sub2).get_parser()], add_help=False) def hello(**kwargs): print("Hello", kwargs) at = argtyper.ArgTyper(hello, arg_defaults={"amount": 2}) at()
import argtyper @argtyper.Argument("amount", "repetitions", help="How often should we say hello?", metavar="reps") @argtyper.Argument("name", "--name", "--n", help="Give me your name", default="Yoda") def hello(name: str, amount: int = 2): print("\n".join([f"Hello {name.upper()}"] * amount)) at = argtyper.ArgTyper(hello, version="This is %(prog)s version 1.3.3.7") at()