paramspecli 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- paramspecli/__init__.py +27 -0
- paramspecli/apstub.py +84 -0
- paramspecli/args.py +110 -0
- paramspecli/cli.py +956 -0
- paramspecli/conv.py +58 -0
- paramspecli/doc.py +368 -0
- paramspecli/fake.py +127 -0
- paramspecli/flags.py +226 -0
- paramspecli/md.py +75 -0
- paramspecli/opts.py +324 -0
- paramspecli/py.typed +0 -0
- paramspecli/util.py +50 -0
- paramspecli-0.2.1.dist-info/METADATA +88 -0
- paramspecli-0.2.1.dist-info/RECORD +16 -0
- paramspecli-0.2.1.dist-info/WHEEL +4 -0
- paramspecli-0.2.1.dist-info/licenses/LICENSE +21 -0
paramspecli/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Type-safe facade for the venerable argparse"""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.2.1"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from .args import argument as argument
|
|
7
|
+
from .cli import Action as Action
|
|
8
|
+
from .cli import CallableGroup as CallableGroup
|
|
9
|
+
from .cli import Command as Command
|
|
10
|
+
from .cli import Config as Config
|
|
11
|
+
from .cli import Group as Group
|
|
12
|
+
from .cli import Handler as Handler
|
|
13
|
+
from .cli import Route as Route
|
|
14
|
+
from .cli import help_action as help_action
|
|
15
|
+
from .cli import version_action as version_action
|
|
16
|
+
from .conv import PathConv as PathConv
|
|
17
|
+
from .fake import Const as Const
|
|
18
|
+
from .fake import Context as Context
|
|
19
|
+
from .fake import deprecated as deprecated
|
|
20
|
+
from .fake import required as required
|
|
21
|
+
from .fake import t as t
|
|
22
|
+
from .flags import count as count
|
|
23
|
+
from .flags import flag as flag
|
|
24
|
+
from .flags import repeated_flag as repeated_flag
|
|
25
|
+
from .flags import switch as switch
|
|
26
|
+
from .opts import option as option
|
|
27
|
+
from .opts import repeated_option as repeated_option
|
paramspecli/apstub.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Protocols are used since some of the needed argparse classes are internal, e.g. _SubParsersAction
|
|
2
|
+
# Based on a typeshed with a small changes and omissions.
|
|
3
|
+
import argparse
|
|
4
|
+
from typing import Any, Callable, Iterable, NoReturn, Protocol
|
|
5
|
+
|
|
6
|
+
type TypeConverter[T] = Callable[[str], T]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SupportsAddArgument(Protocol):
|
|
10
|
+
def add_argument(
|
|
11
|
+
self,
|
|
12
|
+
*names: str,
|
|
13
|
+
nargs: int | str | None = ...,
|
|
14
|
+
const: Any = ...,
|
|
15
|
+
default: Any = ...,
|
|
16
|
+
type: TypeConverter[Any] = ...,
|
|
17
|
+
choices: Iterable[Any] | None = ...,
|
|
18
|
+
action: str | type[argparse.Action] = ...,
|
|
19
|
+
required: bool = ...,
|
|
20
|
+
help: str | None = ...,
|
|
21
|
+
metavar: str | tuple[str, ...] | None = ...,
|
|
22
|
+
dest: str | None = ...,
|
|
23
|
+
version: str = ...,
|
|
24
|
+
**kwargs: Any,
|
|
25
|
+
) -> argparse.Action: ...
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SupportsSetDefaults(Protocol):
|
|
29
|
+
def set_defaults(self, **kwargs: Any) -> None: ...
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SupportsAddOneofGroup(Protocol):
|
|
33
|
+
def add_mutually_exclusive_group(self, *, required: bool = ...) -> SupportsAddArgument: ...
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class SupportsAddParser(Protocol):
|
|
37
|
+
def add_parser(
|
|
38
|
+
self,
|
|
39
|
+
name: str,
|
|
40
|
+
*,
|
|
41
|
+
# own
|
|
42
|
+
help: str | None = ...,
|
|
43
|
+
aliases: tuple[str, ...] = ...,
|
|
44
|
+
# of ArgumentParser
|
|
45
|
+
usage: str | None = ...,
|
|
46
|
+
description: str | None = ...,
|
|
47
|
+
epilog: str | None = ...,
|
|
48
|
+
formatter_class: type[argparse.HelpFormatter] = ...,
|
|
49
|
+
allow_abbrev: bool = ...,
|
|
50
|
+
# NOTE: exit_on_error is broken in argparse. in same cases it's exit anyway
|
|
51
|
+
exit_on_error: bool = ...,
|
|
52
|
+
prog: str | None = ...,
|
|
53
|
+
add_help: bool = ...,
|
|
54
|
+
# untyped rest
|
|
55
|
+
**kwargs: Any,
|
|
56
|
+
) -> "ArgumentParserLike": ...
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class SupportsAddArgumentGroup(Protocol):
|
|
60
|
+
def add_argument_group(self, title: str | None = ..., description: str | None = ...) -> "ArgumentGroupLike": ...
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ArgumentParserLike(
|
|
64
|
+
SupportsAddArgument, SupportsAddArgumentGroup, SupportsAddOneofGroup, SupportsSetDefaults, Protocol
|
|
65
|
+
):
|
|
66
|
+
def add_subparsers(
|
|
67
|
+
self,
|
|
68
|
+
*,
|
|
69
|
+
title: str = ...,
|
|
70
|
+
prog: str | None = ...,
|
|
71
|
+
# parser_class: type[argparse.ArgumentParser],
|
|
72
|
+
parser_class: type[Any],
|
|
73
|
+
required: bool = ...,
|
|
74
|
+
help: str | None = ...,
|
|
75
|
+
metavar: str | None = ...,
|
|
76
|
+
description: str | None = ...,
|
|
77
|
+
dest: str | None = None,
|
|
78
|
+
) -> SupportsAddParser: ...
|
|
79
|
+
|
|
80
|
+
def print_help(self) -> None: ...
|
|
81
|
+
def exit(self, status: int = ..., message: str | None = ...) -> NoReturn: ...
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class ArgumentGroupLike(SupportsAddArgument, SupportsAddOneofGroup, Protocol): ...
|
paramspecli/args.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from typing import Any, Iterable, Literal, overload
|
|
2
|
+
|
|
3
|
+
from .apstub import TypeConverter
|
|
4
|
+
from .fake import Argument
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
@overload
|
|
9
|
+
def argument(
|
|
10
|
+
metavar: str,
|
|
11
|
+
*,
|
|
12
|
+
help: str | Literal[False] | None = None,
|
|
13
|
+
choices: Iterable[str] | None = None,
|
|
14
|
+
) -> Argument[str, str]: ...
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## nargs
|
|
18
|
+
@overload
|
|
19
|
+
def argument(
|
|
20
|
+
metavar: str,
|
|
21
|
+
*,
|
|
22
|
+
nargs: int | Literal["*", "+"],
|
|
23
|
+
help: str | Literal[False] | None = None,
|
|
24
|
+
choices: Iterable[str] | None = None,
|
|
25
|
+
) -> Argument[list[str], list[str]]: ...
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## optional
|
|
29
|
+
@overload
|
|
30
|
+
def argument(
|
|
31
|
+
metavar: str,
|
|
32
|
+
*,
|
|
33
|
+
nargs: Literal["?"],
|
|
34
|
+
help: str | Literal[False] | None = None,
|
|
35
|
+
choices: Iterable[str] | None = None,
|
|
36
|
+
) -> Argument[str, None]: ...
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## optional, default: D
|
|
40
|
+
@overload
|
|
41
|
+
def argument[D](
|
|
42
|
+
metavar: str,
|
|
43
|
+
*,
|
|
44
|
+
nargs: Literal["?"],
|
|
45
|
+
default: D,
|
|
46
|
+
help: str | Literal[False] | None = None,
|
|
47
|
+
choices: Iterable[str] | None = None,
|
|
48
|
+
) -> Argument[str, D]: ...
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## type: T
|
|
52
|
+
@overload
|
|
53
|
+
def argument[T](
|
|
54
|
+
metavar: str,
|
|
55
|
+
*,
|
|
56
|
+
type: TypeConverter[T],
|
|
57
|
+
help: str | Literal[False] | None = None,
|
|
58
|
+
choices: Iterable[T] | None = None,
|
|
59
|
+
) -> Argument[T, T]: ...
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## type: T, nargs
|
|
63
|
+
@overload
|
|
64
|
+
def argument[T](
|
|
65
|
+
metavar: str,
|
|
66
|
+
*,
|
|
67
|
+
type: TypeConverter[T],
|
|
68
|
+
nargs: int | Literal["*", "+"],
|
|
69
|
+
help: str | Literal[False] | None = None,
|
|
70
|
+
choices: Iterable[T] | None = None,
|
|
71
|
+
) -> Argument[list[T], list[T]]: ...
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## type: T, optional
|
|
75
|
+
@overload
|
|
76
|
+
def argument[T](
|
|
77
|
+
metavar: str,
|
|
78
|
+
*,
|
|
79
|
+
type: TypeConverter[T],
|
|
80
|
+
nargs: Literal["?"],
|
|
81
|
+
help: str | Literal[False] | None = None,
|
|
82
|
+
choices: Iterable[T] | None = None,
|
|
83
|
+
) -> Argument[T, None]: ...
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## type: T, optional, default: str | D
|
|
87
|
+
# default is parsed if string
|
|
88
|
+
@overload
|
|
89
|
+
def argument[T, D](
|
|
90
|
+
metavar: str,
|
|
91
|
+
*,
|
|
92
|
+
type: TypeConverter[T],
|
|
93
|
+
nargs: Literal["?"],
|
|
94
|
+
help: str | Literal[False] | None = None,
|
|
95
|
+
default: str | D,
|
|
96
|
+
choices: Iterable[T] | None = None,
|
|
97
|
+
) -> Argument[T, T | D]: ...
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def argument(
|
|
101
|
+
metavar: str,
|
|
102
|
+
*,
|
|
103
|
+
type: TypeConverter[Any] | None = None,
|
|
104
|
+
help: str | Literal[False] | None = None,
|
|
105
|
+
nargs: int | Literal["*", "+", "?"] | None = None,
|
|
106
|
+
default: Any | None = None,
|
|
107
|
+
choices: Iterable[Any] | None = None,
|
|
108
|
+
) -> Argument[Any, Any]:
|
|
109
|
+
"""Positional argument. Always required, unless made optional via `nargs="?"`."""
|
|
110
|
+
return Argument(metavar, help=help, type=type, choices=choices, nargs=nargs, default=default)
|