Skip to content

Supported Type

in a file named src.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from enum import Enum
from typing import List, Tuple

from arger import Arger
from tests.utils import _reprint


class Choice(Enum):
    one = '1. One'
    two = '2. Two'

    def __str__(self):
        """by implementing this function one can control the enum-display in help string"""
        return self.name

arger = Arger(prog='pytest', description="App Description goes here")

container = []


@arger.add_cmd
def cmd1(
    an_int: int,
    an_str: str,
    a_tuple: Tuple[str, str, str],  # nargs: 3 -> consume 3
    a_var_tuple: Tuple[str, ...],  # nargs: +  -> consume one or more
    an_enum=Choice.one,
    optional_str='',
    optional_int=0,
    optional_tpl=(),
):
    """Example function with types documented in the docstring."""
    _reprint(**locals())


@arger.add_cmd
def cmd2(
    a_list: List[int],  # nargs='*': -> capture many args
    m_opt=False,
    y_opt=False,
    my=False,
):
    """A script with three optional values.

    :param a_list: catch all positional arguments
    :param m_opt: the m_opt helptext
    :param y_opt: the y_opt helptext
    :param my: the my helptext
    """
    _reprint(**locals())


if __name__ == '__main__':
    arger.run()