preparse 2.0.0.dev5__tar.gz → 2.0.0.dev7__tar.gz
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.
- {preparse-2.0.0.dev5/src/preparse.egg-info → preparse-2.0.0.dev7}/PKG-INFO +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/docs/v1.0.rst +6 -6
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/pyproject.toml +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_items/Bundle.py +5 -5
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_items/Item.py +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_items/Long.py +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_items/Option.py +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_items/Positional.py +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_items/Special.py +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_processing/__init__.py +14 -14
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_processing/digesting.py +22 -42
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_processing/parsing.py +40 -32
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/core/Optdict.py +4 -3
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/core/PreParser.py +37 -37
- preparse-2.0.0.dev7/src/preparse/core/__init__.py +5 -0
- preparse-2.0.0.dev7/src/preparse/core/warnings.py +152 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/tests/data.toml +176686 -176640
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/tests/test_data_toml.py +16 -2
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/tests/test_enums.py +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/tests/test_expit_toml.py +1 -1
- preparse-2.0.0.dev7/src/preparse/tests/test_optdict.py +22 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/tests/test_preparser.py +4 -3
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7/src/preparse.egg-info}/PKG-INFO +1 -1
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse.egg-info/SOURCES.txt +3 -11
- preparse-2.0.0.dev5/src/preparse/core/PreparseWarning.py +0 -6
- preparse-2.0.0.dev5/src/preparse/core/__init__.py +0 -4
- preparse-2.0.0.dev5/src/preparse/tests/test_optdict.py +0 -21
- preparse-2.0.0.dev5/src/preparse/warners/AmbiguousOptionWarner.py +0 -38
- preparse-2.0.0.dev5/src/preparse/warners/DualWarner.py +0 -33
- preparse-2.0.0.dev5/src/preparse/warners/InvalidOptionWarner.py +0 -14
- preparse-2.0.0.dev5/src/preparse/warners/LongonlyWarner.py +0 -13
- preparse-2.0.0.dev5/src/preparse/warners/RequiredArgumentWarner.py +0 -14
- preparse-2.0.0.dev5/src/preparse/warners/UnallowedArgumentWarner.py +0 -25
- preparse-2.0.0.dev5/src/preparse/warners/WarnerABC.py +0 -60
- preparse-2.0.0.dev5/src/preparse/warners/__init__.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/LICENSE.txt +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/MANIFEST.in +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/README.rst +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/setup.cfg +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/__init__.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_items/__init__.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_processing/deparsing.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_processing/pulling.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_utils/__init__.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/_utils/dataprop.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/core/Click.py +0 -0
- /preparse-2.0.0.dev5/src/preparse/enums/__init__.py → /preparse-2.0.0.dev7/src/preparse/core/enums.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/tests/__init__.py +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse/tests/expit.toml +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse.egg-info/dependency_links.txt +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse.egg-info/requires.txt +0 -0
- {preparse-2.0.0.dev5 → preparse-2.0.0.dev7}/src/preparse.egg-info/top_level.txt +0 -0
|
@@ -64,7 +64,7 @@ Features
|
|
|
64
64
|
The PreParser class
|
|
65
65
|
~~~~~~~~~~~~~~~~~~~
|
|
66
66
|
|
|
67
|
-
``class preparse.PreParser(*, allowslong: Any = True, allowsshort: Any = True, bundling: Any = Tuning.MAINTAIN, expandsabbr: Any = True, expectsabbr: Any = True, expectsposix: Any = False,
|
|
67
|
+
``class preparse.PreParser(*, allowslong: Any = True, allowsshort: Any = True, bundling: Any = Tuning.MAINTAIN, expandsabbr: Any = True, expectsabbr: Any = True, expectsposix: Any = False, optdict: Any = (), prog: Any = None, reconcilesorders: Any = True, special: Any = preparse.Tuning.MAINTAIN, warn: Callable = str)``
|
|
68
68
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
69
69
|
|
|
70
70
|
This class is the centerpiece of the preparse. Its behaviour follows the principles of getopt from C.
|
|
@@ -109,7 +109,7 @@ This boolean property determines whether abbreviations of long options are expec
|
|
|
109
109
|
|
|
110
110
|
This boolean property determines whether the order of arguments to conform to the POSIX standard, i.e. all arguments after the first positional argument also being positonal.
|
|
111
111
|
|
|
112
|
-
``
|
|
112
|
+
``optdict: preparse.Optdict``
|
|
113
113
|
"""""""""""""""""""""""""""""
|
|
114
114
|
|
|
115
115
|
This property holds a dict-like object.
|
|
@@ -143,7 +143,7 @@ POSIX and the interleaving of options with positonal arguments, should be enforc
|
|
|
143
143
|
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
144
144
|
|
|
145
145
|
This method alters the current instance to reflect a ``click.Command`` object.
|
|
146
|
-
Concretely the
|
|
146
|
+
Concretely the optdict property is changed.
|
|
147
147
|
|
|
148
148
|
``reflectClickContext(ctx: click.Context) -> None``
|
|
149
149
|
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -202,15 +202,15 @@ This property determines if the ``reflectClickContext`` method of parser is to b
|
|
|
202
202
|
|
|
203
203
|
This property holds the parser to be embedded.
|
|
204
204
|
|
|
205
|
-
The
|
|
205
|
+
The Optdict class
|
|
206
206
|
~~~~~~~~~~~~~~~~~
|
|
207
207
|
|
|
208
|
-
``class preparse.
|
|
208
|
+
``class preparse.Optdict``
|
|
209
209
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
210
210
|
|
|
211
211
|
This class is a subclass of ``datahold.HoldDict[str, preparse.Nargs]``
|
|
212
212
|
with strings as keys and with ``preparse.Nargs`` as values.
|
|
213
|
-
It is designed for ``preparse.PreParser.
|
|
213
|
+
It is designed for ``preparse.PreParser.optdict``.
|
|
214
214
|
|
|
215
215
|
The Enums
|
|
216
216
|
~~~~~~~~~
|
|
@@ -5,7 +5,7 @@ import setdoc
|
|
|
5
5
|
from preparse._items.Item import Item
|
|
6
6
|
from preparse._items.Option import Option
|
|
7
7
|
from preparse._utils.dataprop import dataprop
|
|
8
|
-
from preparse.enums import *
|
|
8
|
+
from preparse.core.enums import *
|
|
9
9
|
|
|
10
10
|
__all__ = ["Bundle"]
|
|
11
11
|
|
|
@@ -32,7 +32,7 @@ class Bundle(Option):
|
|
|
32
32
|
self.right = right
|
|
33
33
|
|
|
34
34
|
@classmethod
|
|
35
|
-
def
|
|
35
|
+
def _split_allowslong(cls: type, chars: str) -> list[str]:
|
|
36
36
|
ans: list[str]
|
|
37
37
|
x: str
|
|
38
38
|
ans = list()
|
|
@@ -73,12 +73,12 @@ class Bundle(Option):
|
|
|
73
73
|
else:
|
|
74
74
|
return ["-" + self.chars, self.right]
|
|
75
75
|
|
|
76
|
-
def split(self: Self, *,
|
|
76
|
+
def split(self: Self, *, allowslong: bool) -> list[Item]:
|
|
77
77
|
ans: list[Self]
|
|
78
78
|
parts: list[str]
|
|
79
79
|
x: str
|
|
80
|
-
if
|
|
81
|
-
parts = self.
|
|
80
|
+
if allowslong:
|
|
81
|
+
parts = self._split_allowslong(self.chars)
|
|
82
82
|
else:
|
|
83
83
|
parts = self._split_shortonly(self.chars)
|
|
84
84
|
ans = list()
|
|
@@ -7,7 +7,7 @@ from preparse._processing.digesting import *
|
|
|
7
7
|
from preparse._processing.parsing import *
|
|
8
8
|
from preparse._processing.pulling import *
|
|
9
9
|
from preparse._utils import *
|
|
10
|
-
from preparse.enums import *
|
|
10
|
+
from preparse.core.enums import *
|
|
11
11
|
|
|
12
12
|
__all__ = ["process"]
|
|
13
13
|
|
|
@@ -15,15 +15,15 @@ __all__ = ["process"]
|
|
|
15
15
|
def process(
|
|
16
16
|
args: Optional[Iterable] = None,
|
|
17
17
|
*,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
allowslong: bool,
|
|
19
|
+
allowsshort: bool,
|
|
20
20
|
bundling: Tuning,
|
|
21
21
|
expandsabbr: bool,
|
|
22
22
|
expectsabbr: bool,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
expectsposix: bool,
|
|
24
|
+
optdict: dict,
|
|
25
25
|
prog: str,
|
|
26
|
-
|
|
26
|
+
reconcilesorders: bool,
|
|
27
27
|
special: Tuning,
|
|
28
28
|
warn: FunctionType,
|
|
29
29
|
) -> list[str]:
|
|
@@ -32,21 +32,21 @@ def process(
|
|
|
32
32
|
items = pull(args)
|
|
33
33
|
items = parse(
|
|
34
34
|
items,
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
allowslong=allowslong,
|
|
36
|
+
allowsshort=allowsshort,
|
|
37
|
+
expandsabbr=expandsabbr,
|
|
37
38
|
expectsabbr=expectsabbr,
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
expectsposix=expectsposix,
|
|
40
|
+
optdict=optdict,
|
|
40
41
|
prog=prog,
|
|
41
42
|
warn=warn,
|
|
42
43
|
)
|
|
43
44
|
items = digest(
|
|
44
45
|
items,
|
|
45
|
-
|
|
46
|
+
allowslong=allowslong,
|
|
46
47
|
bundling=bundling,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
reconcilesOrders=reconcilesOrders,
|
|
48
|
+
expectsposix=expectsposix,
|
|
49
|
+
reconcilesorders=reconcilesorders,
|
|
50
50
|
special=special,
|
|
51
51
|
)
|
|
52
52
|
return deparse(items)
|
|
@@ -2,11 +2,11 @@ from typing import *
|
|
|
2
2
|
|
|
3
3
|
from preparse._items.Bundle import Bundle
|
|
4
4
|
from preparse._items.Item import Item
|
|
5
|
-
from preparse._items.Long import Long
|
|
6
5
|
from preparse._items.Option import Option
|
|
7
6
|
from preparse._items.Positional import Positional
|
|
8
7
|
from preparse._items.Special import Special
|
|
9
|
-
from preparse.enums import *
|
|
8
|
+
from preparse.core.enums import *
|
|
9
|
+
from preparse.core.warnings import *
|
|
10
10
|
|
|
11
11
|
__all__ = ["digest"]
|
|
12
12
|
|
|
@@ -14,62 +14,42 @@ __all__ = ["digest"]
|
|
|
14
14
|
def digest(
|
|
15
15
|
items: list[Item],
|
|
16
16
|
*,
|
|
17
|
-
|
|
17
|
+
allowslong: bool,
|
|
18
18
|
bundling: Tuning,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
reconcilesOrders: bool,
|
|
19
|
+
expectsposix: bool,
|
|
20
|
+
reconcilesorders: bool,
|
|
22
21
|
special: Tuning,
|
|
23
22
|
) -> list[Item]:
|
|
24
23
|
ans: list[Item]
|
|
25
24
|
ans = list(items)
|
|
26
|
-
|
|
27
|
-
ans,
|
|
28
|
-
expandsabbr=expandsabbr,
|
|
29
|
-
)
|
|
25
|
+
|
|
30
26
|
ans = digest_special(
|
|
31
27
|
ans,
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
expectsposix=expectsposix,
|
|
29
|
+
reconcilesorders=reconcilesorders,
|
|
34
30
|
special=special,
|
|
35
31
|
)
|
|
36
32
|
ans = digest_order(
|
|
37
33
|
ans,
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
expectsposix=expectsposix,
|
|
35
|
+
reconcilesorders=reconcilesorders,
|
|
40
36
|
)
|
|
41
37
|
ans = digest_bundling(
|
|
42
38
|
ans,
|
|
43
39
|
bundling=bundling,
|
|
44
|
-
|
|
40
|
+
allowslong=allowslong,
|
|
45
41
|
)
|
|
46
42
|
return ans
|
|
47
43
|
|
|
48
44
|
|
|
49
|
-
def digest_abbr(
|
|
50
|
-
items: list[Item],
|
|
51
|
-
*,
|
|
52
|
-
expandsabbr: bool,
|
|
53
|
-
) -> list[Item]:
|
|
54
|
-
ans: list[Item]
|
|
55
|
-
item: Item
|
|
56
|
-
ans = list(items)
|
|
57
|
-
if not expandsabbr:
|
|
58
|
-
return ans
|
|
59
|
-
for item in ans:
|
|
60
|
-
if isinstance(item, Long):
|
|
61
|
-
item.abbrlen = None
|
|
62
|
-
return ans
|
|
63
|
-
|
|
64
|
-
|
|
65
45
|
def digest_bundling(
|
|
66
46
|
items: list[Item],
|
|
67
47
|
*,
|
|
68
|
-
|
|
48
|
+
allowslong: bool,
|
|
69
49
|
bundling: Tuning,
|
|
70
50
|
) -> list[Item]:
|
|
71
51
|
if bundling == Tuning.MINIMIZE:
|
|
72
|
-
return digest_bundling_min(items,
|
|
52
|
+
return digest_bundling_min(items, allowslong=allowslong)
|
|
73
53
|
if bundling == Tuning.MAXIMIZE:
|
|
74
54
|
return digest_bundling_max(items)
|
|
75
55
|
return items
|
|
@@ -78,14 +58,14 @@ def digest_bundling(
|
|
|
78
58
|
def digest_bundling_min(
|
|
79
59
|
items: list[Item],
|
|
80
60
|
*,
|
|
81
|
-
|
|
61
|
+
allowslong: bool,
|
|
82
62
|
) -> list[Item]:
|
|
83
63
|
ans: list[Item]
|
|
84
64
|
item: Item
|
|
85
65
|
ans = list()
|
|
86
66
|
for item in items:
|
|
87
67
|
if isinstance(item, Bundle):
|
|
88
|
-
ans += item.split(
|
|
68
|
+
ans += item.split(allowslong=allowslong)
|
|
89
69
|
else:
|
|
90
70
|
ans.append(item)
|
|
91
71
|
return ans
|
|
@@ -116,16 +96,16 @@ def digest_bundling_max(items: list[Item]) -> list[Item]:
|
|
|
116
96
|
def digest_order(
|
|
117
97
|
items: list[Item],
|
|
118
98
|
*,
|
|
119
|
-
|
|
120
|
-
|
|
99
|
+
expectsposix: bool,
|
|
100
|
+
reconcilesorders: bool,
|
|
121
101
|
) -> list[Item]:
|
|
122
102
|
ans: list[Item]
|
|
123
103
|
comp: bool
|
|
124
104
|
index: int
|
|
125
105
|
ans = list(items)
|
|
126
|
-
if not
|
|
106
|
+
if not reconcilesorders:
|
|
127
107
|
return ans
|
|
128
|
-
if not
|
|
108
|
+
if not expectsposix:
|
|
129
109
|
ans.sort(key=digest_order_key)
|
|
130
110
|
return ans
|
|
131
111
|
index = len(ans)
|
|
@@ -187,8 +167,8 @@ def digest_special_max(items: list[Item]) -> list[Item]:
|
|
|
187
167
|
def digest_special_min(
|
|
188
168
|
items: list[Item],
|
|
189
169
|
*,
|
|
190
|
-
|
|
191
|
-
|
|
170
|
+
expectsposix: bool,
|
|
171
|
+
reconcilesorders: bool,
|
|
192
172
|
) -> list[Item]:
|
|
193
173
|
ans: list[Item]
|
|
194
174
|
index: int
|
|
@@ -196,7 +176,7 @@ def digest_special_min(
|
|
|
196
176
|
isposix: bool
|
|
197
177
|
ans = list(items)
|
|
198
178
|
isdel = True
|
|
199
|
-
isposix =
|
|
179
|
+
isposix = expectsposix and not reconcilesorders
|
|
200
180
|
index = len(items)
|
|
201
181
|
while True:
|
|
202
182
|
index -= 1
|
|
@@ -7,14 +7,16 @@ from preparse._items.Long import Long
|
|
|
7
7
|
from preparse._items.Option import Option
|
|
8
8
|
from preparse._items.Positional import Positional
|
|
9
9
|
from preparse._items.Special import Special
|
|
10
|
-
from preparse.
|
|
11
|
-
from preparse.
|
|
12
|
-
from preparse.warners.InvalidOptionWarner import InvalidOptionWarner as PIOW
|
|
13
|
-
from preparse.warners.RequiredArgumentWarner import RequiredArgumentWarner as PRAW
|
|
14
|
-
from preparse.warners.UnallowedArgumentWarner import UnallowedArgumentWarner as PUAW
|
|
10
|
+
from preparse.core import warnings
|
|
11
|
+
from preparse.core.enums import *
|
|
15
12
|
|
|
16
13
|
__all__ = ["parse"]
|
|
17
14
|
|
|
15
|
+
PAOW = warnings.PreparseAmbiguousOptionWarning
|
|
16
|
+
PIOW = warnings.PreparseInvalidOptionWarning
|
|
17
|
+
PUAW = warnings.PreparseUnallowedArgumentWarning
|
|
18
|
+
PRAW = warnings.PreparseRequiredArgumentWarning
|
|
19
|
+
|
|
18
20
|
|
|
19
21
|
def parse(args: list[str], **kwargs: Any) -> list[Item]:
|
|
20
22
|
return list(parse_generator(args, **kwargs))
|
|
@@ -24,7 +26,7 @@ def parse_bundling(
|
|
|
24
26
|
arg: str,
|
|
25
27
|
*,
|
|
26
28
|
cause: FunctionType,
|
|
27
|
-
|
|
29
|
+
optdict: dict,
|
|
28
30
|
) -> Bundle:
|
|
29
31
|
ans: Bundle
|
|
30
32
|
x: int
|
|
@@ -35,7 +37,7 @@ def parse_bundling(
|
|
|
35
37
|
continue
|
|
36
38
|
ans.chars += y
|
|
37
39
|
try:
|
|
38
|
-
ans.nargs =
|
|
40
|
+
ans.nargs = optdict["-" + y]
|
|
39
41
|
except KeyError:
|
|
40
42
|
cause(PIOW, option=y, islong=False)
|
|
41
43
|
ans.nargs = Nargs.NO_ARGUMENT
|
|
@@ -62,11 +64,12 @@ def parse_cause(
|
|
|
62
64
|
def parse_generator(
|
|
63
65
|
items: list[Positional],
|
|
64
66
|
*,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
allowslong: bool,
|
|
68
|
+
allowsshort: bool,
|
|
69
|
+
expandsabbr: bool,
|
|
67
70
|
expectsabbr: bool,
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
expectsposix: bool,
|
|
72
|
+
optdict: dict,
|
|
70
73
|
prog: str,
|
|
71
74
|
warn: FunctionType,
|
|
72
75
|
) -> Generator[Any, Any, Any]:
|
|
@@ -74,7 +77,7 @@ def parse_generator(
|
|
|
74
77
|
cause: FunctionType
|
|
75
78
|
last: Optional[Option]
|
|
76
79
|
item: Positional
|
|
77
|
-
broken = not (
|
|
80
|
+
broken = not (allowslong or allowsshort)
|
|
78
81
|
cause = parse_cause(prog=prog, warn=warn)
|
|
79
82
|
last = None
|
|
80
83
|
for item in items:
|
|
@@ -96,15 +99,16 @@ def parse_generator(
|
|
|
96
99
|
if item.isobvious():
|
|
97
100
|
# if the item is positional
|
|
98
101
|
yield item
|
|
99
|
-
broken =
|
|
102
|
+
broken = expectsposix
|
|
100
103
|
continue
|
|
101
104
|
last = parse_option(
|
|
102
105
|
item.value,
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
allowslong=allowslong,
|
|
107
|
+
allowsshort=allowsshort,
|
|
105
108
|
cause=cause,
|
|
109
|
+
expandsabbr=expandsabbr,
|
|
106
110
|
expectsabbr=expectsabbr,
|
|
107
|
-
|
|
111
|
+
optdict=optdict,
|
|
108
112
|
)
|
|
109
113
|
if not last.ishungry():
|
|
110
114
|
yield last
|
|
@@ -122,21 +126,22 @@ def parse_generator(
|
|
|
122
126
|
def parse_islong(
|
|
123
127
|
arg: str,
|
|
124
128
|
*,
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
allowslong: bool,
|
|
130
|
+
allowsshort: bool,
|
|
127
131
|
) -> bool:
|
|
128
|
-
if
|
|
132
|
+
if allowslong and allowsshort:
|
|
129
133
|
return arg.startswith("--")
|
|
130
134
|
else:
|
|
131
|
-
return not
|
|
135
|
+
return not allowsshort
|
|
132
136
|
|
|
133
137
|
|
|
134
138
|
def parse_long(
|
|
135
139
|
arg: str,
|
|
136
140
|
*,
|
|
137
141
|
cause: FunctionType,
|
|
142
|
+
expandsabbr: bool,
|
|
138
143
|
expectsabbr: bool,
|
|
139
|
-
|
|
144
|
+
optdict: dict,
|
|
140
145
|
) -> Long:
|
|
141
146
|
ans: Long
|
|
142
147
|
parts: list[str]
|
|
@@ -146,13 +151,10 @@ def parse_long(
|
|
|
146
151
|
ans.joined = True
|
|
147
152
|
ans.right = parts.pop()
|
|
148
153
|
ans.abbrlen = len(ans.fullkey)
|
|
149
|
-
if ans.fullkey in
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return ans
|
|
154
|
-
if expectsabbr:
|
|
155
|
-
parts = parse_long_startswith(ans.abbr, keys=optDict.keys())
|
|
154
|
+
if ans.fullkey in optdict.keys():
|
|
155
|
+
parts = [ans.fullkey]
|
|
156
|
+
elif expectsabbr:
|
|
157
|
+
parts = parse_long_startswith(ans.abbr, keys=optdict.keys())
|
|
156
158
|
else:
|
|
157
159
|
parts = list() # can be assumed
|
|
158
160
|
if len(parts) == 0:
|
|
@@ -164,7 +166,11 @@ def parse_long(
|
|
|
164
166
|
cause(PAOW, option=arg, possibilities=parts)
|
|
165
167
|
return ans
|
|
166
168
|
(ans.fullkey,) = parts
|
|
167
|
-
|
|
169
|
+
if expandsabbr:
|
|
170
|
+
ans.abbrlen = len(ans.fullkey)
|
|
171
|
+
ans.nargs = optdict[ans.fullkey]
|
|
172
|
+
if (ans.nargs == Nargs.NO_ARGUMENT) and (ans.right is not None):
|
|
173
|
+
cause(PUAW, option=ans.fullkey)
|
|
168
174
|
return ans
|
|
169
175
|
|
|
170
176
|
|
|
@@ -186,20 +192,22 @@ def parse_option(
|
|
|
186
192
|
arg: str,
|
|
187
193
|
*,
|
|
188
194
|
cause: FunctionType,
|
|
195
|
+
expandsabbr: bool,
|
|
189
196
|
expectsabbr: bool,
|
|
190
|
-
|
|
197
|
+
optdict: dict,
|
|
191
198
|
**kwargs: Any,
|
|
192
199
|
) -> Option:
|
|
193
200
|
if parse_islong(arg, **kwargs):
|
|
194
201
|
return parse_long(
|
|
195
202
|
arg,
|
|
196
203
|
cause=cause,
|
|
204
|
+
expandsabbr=expandsabbr,
|
|
197
205
|
expectsabbr=expectsabbr,
|
|
198
|
-
|
|
206
|
+
optdict=optdict,
|
|
199
207
|
)
|
|
200
208
|
else:
|
|
201
209
|
return parse_bundling(
|
|
202
210
|
arg,
|
|
203
211
|
cause=cause,
|
|
204
|
-
|
|
212
|
+
optdict=optdict,
|
|
205
213
|
)
|
|
@@ -6,12 +6,13 @@ import setdoc
|
|
|
6
6
|
from datarepr import datarepr
|
|
7
7
|
from frozendict import frozendict
|
|
8
8
|
|
|
9
|
-
from preparse.enums import *
|
|
9
|
+
from preparse.core.enums import *
|
|
10
|
+
from preparse.core.warnings import *
|
|
10
11
|
|
|
11
|
-
__all__ = ["
|
|
12
|
+
__all__ = ["Optdict"]
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
class
|
|
15
|
+
class Optdict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
|
|
15
16
|
__slots__ = ()
|
|
16
17
|
|
|
17
18
|
data: frozendict[str, Nargs]
|