cli2 2.7.0__tar.gz → 2.7.2__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.
- {cli2-2.7.0/cli2.egg-info → cli2-2.7.2}/PKG-INFO +1 -1
- {cli2-2.7.0 → cli2-2.7.2}/cli2/command.py +18 -14
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test_command.py +20 -5
- {cli2-2.7.0 → cli2-2.7.2/cli2.egg-info}/PKG-INFO +1 -1
- {cli2-2.7.0 → cli2-2.7.2}/setup.py +1 -1
- {cli2-2.7.0 → cli2-2.7.2}/MANIFEST.in +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/README.rst +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/classifiers.txt +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/__init__.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/argument.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/cli.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/colors.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/decorators.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/entry_point.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/group.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/node.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/table.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test_cli.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test_decorators.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test_entrypoint.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test_group.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test_inject.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test_node.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2/test_table.py +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/SOURCES.txt +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/dependency_links.txt +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/entry_points.txt +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/requires.txt +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/top_level.txt +0 -0
- {cli2-2.7.0 → cli2-2.7.2}/setup.cfg +0 -0
|
@@ -18,10 +18,11 @@ class Command(EntryPoint, dict):
|
|
|
18
18
|
return super().__new__(cls, *args, **kwargs)
|
|
19
19
|
|
|
20
20
|
def __init__(self, target, name=None, color=None, doc=None, posix=False,
|
|
21
|
-
outfile=None, log=True):
|
|
21
|
+
help_hack=True, outfile=None, log=True):
|
|
22
22
|
self.target = target
|
|
23
23
|
self.posix = posix
|
|
24
24
|
self.parent = None
|
|
25
|
+
self.help_hack = help_hack
|
|
25
26
|
|
|
26
27
|
overrides = getattr(target, 'cli2', {})
|
|
27
28
|
for key, value in overrides.items():
|
|
@@ -153,27 +154,28 @@ class Command(EntryPoint, dict):
|
|
|
153
154
|
|
|
154
155
|
def __call__(self, *argv):
|
|
155
156
|
"""Execute command with args from sysargs."""
|
|
157
|
+
if self.help_hack and '--help' in argv:
|
|
158
|
+
self.exit_code = 1
|
|
159
|
+
return self.help()
|
|
160
|
+
|
|
156
161
|
self.exit_code = 0
|
|
157
162
|
error = self.parse(*argv)
|
|
158
163
|
if error:
|
|
159
164
|
self.exit_code = 1
|
|
160
165
|
return self.help(error=error)
|
|
161
166
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
for arg in self.
|
|
165
|
-
if
|
|
166
|
-
and
|
|
167
|
-
and arg.param.
|
|
168
|
-
|
|
169
|
-
arg.param.
|
|
167
|
+
missing = [
|
|
168
|
+
name
|
|
169
|
+
for name, arg in self.items()
|
|
170
|
+
if name not in self.bound.arguments
|
|
171
|
+
and name not in self.bound.kwargs
|
|
172
|
+
and arg.param.default == arg.param.empty
|
|
173
|
+
and arg.param.kind in (
|
|
174
|
+
arg.param.POSITIONAL_ONLY,
|
|
175
|
+
arg.param.POSITIONAL_OR_KEYWORD,
|
|
170
176
|
)
|
|
171
177
|
]
|
|
172
|
-
if
|
|
173
|
-
missing = [
|
|
174
|
-
arg.param.name
|
|
175
|
-
for arg in required[len(self.bound.args):]
|
|
176
|
-
]
|
|
178
|
+
if missing:
|
|
177
179
|
error = (
|
|
178
180
|
f'missing {len(missing)} required argument'
|
|
179
181
|
f'{"s" if len(missing) > 1 else ""}'
|
|
@@ -187,6 +189,8 @@ class Command(EntryPoint, dict):
|
|
|
187
189
|
if inspect.iscoroutine(result):
|
|
188
190
|
result = asyncio.run(result)
|
|
189
191
|
except TypeError as exc:
|
|
192
|
+
# keeping this as fallback for now, in case the above missing
|
|
193
|
+
# detection doesn't work
|
|
190
194
|
self.exit_code = 1
|
|
191
195
|
if hasattr(self.target, '__name__'):
|
|
192
196
|
rep = getattr(self.target, '__name__')
|
|
@@ -499,10 +499,25 @@ def test_arg_reorder():
|
|
|
499
499
|
|
|
500
500
|
|
|
501
501
|
def test_arg():
|
|
502
|
-
|
|
503
|
-
def call(self, *args, **kwargs):
|
|
504
|
-
return (args, kwargs)
|
|
505
|
-
|
|
506
|
-
cmd = TestCommand(lambda foo: True)
|
|
502
|
+
cmd = Command(lambda foo: foo)
|
|
507
503
|
cmd.arg('bar', position=0)
|
|
508
504
|
assert list(cmd.keys()) == ['bar', 'foo']
|
|
505
|
+
assert cmd('bar', 'foo') == 'foo'
|
|
506
|
+
assert cmd['bar'].value == 'bar'
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def test_helphack():
|
|
510
|
+
class TestCommand(Command):
|
|
511
|
+
def help(self):
|
|
512
|
+
self.help_shown = True
|
|
513
|
+
|
|
514
|
+
def foo(*one): return one
|
|
515
|
+
cmd = TestCommand(foo)
|
|
516
|
+
cmd('a', 'b', '--help')
|
|
517
|
+
assert cmd.exit_code == 1
|
|
518
|
+
assert getattr(cmd, 'help_shown', False)
|
|
519
|
+
|
|
520
|
+
cmd = TestCommand(foo, help_hack=False)
|
|
521
|
+
cmd('a', 'b', '--help')
|
|
522
|
+
assert cmd.exit_code == 0
|
|
523
|
+
assert not getattr(cmd, 'help_shown', False)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|