wizlib 3.1.0__py3-none-any.whl → 3.1.2__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.
Potentially problematic release.
This version of wizlib might be problematic. Click here for more details.
wizlib/app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from argparse import ArgumentError
|
|
1
2
|
import sys
|
|
2
3
|
from dataclasses import dataclass
|
|
3
4
|
import os
|
|
@@ -6,7 +7,7 @@ from pathlib import Path
|
|
|
6
7
|
from wizlib.class_family import ClassFamily
|
|
7
8
|
from wizlib.command import WizHelpCommand
|
|
8
9
|
from wizlib.super_wrapper import SuperWrapper
|
|
9
|
-
from wizlib.parser import WizParser
|
|
10
|
+
from wizlib.parser import WizArgumentError, WizParser
|
|
10
11
|
from wizlib.ui import UI
|
|
11
12
|
|
|
12
13
|
|
|
@@ -44,7 +45,12 @@ class WizApp:
|
|
|
44
45
|
"""Call this from a Python entrypoint"""
|
|
45
46
|
try:
|
|
46
47
|
cls.initialize()
|
|
47
|
-
|
|
48
|
+
try:
|
|
49
|
+
ns = cls.parser.parse_args(args)
|
|
50
|
+
if (ns.command is None) and (not hasattr(ns, 'help')):
|
|
51
|
+
ns = cls.dparser.parse_args(args)
|
|
52
|
+
except ArgumentError as e:
|
|
53
|
+
ns = cls.dparser.parse_args(args)
|
|
48
54
|
app = cls(**vars(ns))
|
|
49
55
|
app.run(**vars(ns))
|
|
50
56
|
except AppCancellation as cancellation:
|
|
@@ -63,14 +69,17 @@ class WizApp:
|
|
|
63
69
|
def initialize(cls):
|
|
64
70
|
"""Set up the parser for the app class"""
|
|
65
71
|
cls.parser = WizParser(prog=cls.name)
|
|
66
|
-
for handler in cls.handlers:
|
|
67
|
-
handler.add_args(cls.parser)
|
|
68
72
|
subparsers = cls.parser.add_subparsers(dest='command')
|
|
69
73
|
for command in cls.base.family_members('name'):
|
|
70
74
|
key = command.get_member_attr('key')
|
|
71
75
|
aliases = [key] if key else []
|
|
72
76
|
subparser = subparsers.add_parser(command.name, aliases=aliases)
|
|
77
|
+
if command.name == cls.base.default:
|
|
78
|
+
cls.dparser = subparser
|
|
73
79
|
command.add_args(subparser)
|
|
80
|
+
for handler in cls.handlers:
|
|
81
|
+
handler.add_args(cls.parser)
|
|
82
|
+
handler.add_args(cls.dparser)
|
|
74
83
|
|
|
75
84
|
def __init__(self, **vals):
|
|
76
85
|
"""Create the app. Only interested in the handlers from the parsed
|
|
@@ -86,12 +95,13 @@ class WizApp:
|
|
|
86
95
|
the command itself and its specific arguments from the values passed
|
|
87
96
|
in."""
|
|
88
97
|
if 'help' in vals:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
ccls = WizHelpCommand
|
|
99
|
+
else:
|
|
100
|
+
c = 'command'
|
|
101
|
+
cname = (vals.pop(c) if c in vals else None) or self.base.default
|
|
102
|
+
ccls = self.base.family_member('name', cname)
|
|
103
|
+
if not ccls:
|
|
104
|
+
raise Exception(f"Unknown command {cname}")
|
|
95
105
|
command = ccls(self, **vals)
|
|
96
106
|
result = command.execute()
|
|
97
107
|
if result:
|
|
@@ -100,3 +110,8 @@ class WizApp:
|
|
|
100
110
|
print()
|
|
101
111
|
if command.status:
|
|
102
112
|
print(command.status, file=sys.stderr)
|
|
113
|
+
|
|
114
|
+
def parse_run(self, *args):
|
|
115
|
+
"""For testing, parse just the command part and tun"""
|
|
116
|
+
ns = self.parser.parse_args(args)
|
|
117
|
+
self.run(**vars(ns))
|
wizlib/parser.py
CHANGED
wizlib/super_wrapper.py
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
wizlib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
wizlib/app.py,sha256=
|
|
2
|
+
wizlib/app.py,sha256=imR_lfyQtYzKObu1tLZVGgJQGmdz43M7E9qAMMokyD4,3962
|
|
3
3
|
wizlib/class_family.py,sha256=tORSVAaPeWTQMcz2DX-MQClj1GQR3vCmkALPXxHa_pk,4506
|
|
4
4
|
wizlib/command.py,sha256=NO1558EYuXxfkpSmX6ljjzae8n8g4w6yytZKTJtigvo,1708
|
|
5
5
|
wizlib/config_handler.py,sha256=hoDavSMiGM_7PAHI8XIwC8nxPWOZDk302ryyjluoLGg,2588
|
|
6
6
|
wizlib/error.py,sha256=ypwdMOYhtgKWd48ccfOX8idmCXmm-Skwx3gkPwqJB3c,46
|
|
7
7
|
wizlib/handler.py,sha256=Oz80aPhDyeY9tdppZ1dvtN-19JU5ydEDVW6jtppVoD4,446
|
|
8
|
-
wizlib/parser.py,sha256=
|
|
8
|
+
wizlib/parser.py,sha256=yLHV0fENeApFomCRWa3I6sB1x4lk1ag4vKejWVsic64,1550
|
|
9
9
|
wizlib/stream_handler.py,sha256=i1EgcBrDiYhFK-CI8At7JtUtMCNunJmSkJLSlili-as,663
|
|
10
|
-
wizlib/super_wrapper.py,sha256=
|
|
10
|
+
wizlib/super_wrapper.py,sha256=msitlfFfEwnrskzTtQBEY975sh9TQPicdLVo67imuqU,315
|
|
11
11
|
wizlib/ui/__init__.py,sha256=ve_p_g4aBujh4jIJMgKkJ6cE5PT0aeY5AgRlneDswGg,4241
|
|
12
12
|
wizlib/ui/shell/__init__.py,sha256=sPrYe4bG_Xf7Nwssx_dqXVk9jeyYBFUjh4oLdlSOeRY,943
|
|
13
13
|
wizlib/ui/shell/line_editor.py,sha256=frpsqU5NggcvEz3XeB8YyqgmlExlyx6K1CKPzvARtPk,7419
|
|
14
14
|
wizlib/ui/shell_ui.py,sha256=f2GErMJg09GPZDS4uK0q8Qq8WEssQFP1dqQyg4ycznI,2029
|
|
15
15
|
wizlib/ui_handler.py,sha256=JoZadtw9DKAtGvHKP3_BJF2NaYqmcQYNdsY4PeRnOjg,634
|
|
16
16
|
wizlib/util.py,sha256=x1SyL3iXot0ET2r8Jjb2ySTd_J-3Uu7J1b_CHvFgzew,156
|
|
17
|
-
wizlib-3.1.
|
|
18
|
-
wizlib-3.1.
|
|
19
|
-
wizlib-3.1.
|
|
17
|
+
wizlib-3.1.2.dist-info/METADATA,sha256=4HzwBU_sp2F4ycdTb1XvCTDO5i7DeIMdOhl63JfCzNs,1780
|
|
18
|
+
wizlib-3.1.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
19
|
+
wizlib-3.1.2.dist-info/RECORD,,
|
|
File without changes
|