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.
Files changed (31) hide show
  1. {cli2-2.7.0/cli2.egg-info → cli2-2.7.2}/PKG-INFO +1 -1
  2. {cli2-2.7.0 → cli2-2.7.2}/cli2/command.py +18 -14
  3. {cli2-2.7.0 → cli2-2.7.2}/cli2/test_command.py +20 -5
  4. {cli2-2.7.0 → cli2-2.7.2/cli2.egg-info}/PKG-INFO +1 -1
  5. {cli2-2.7.0 → cli2-2.7.2}/setup.py +1 -1
  6. {cli2-2.7.0 → cli2-2.7.2}/MANIFEST.in +0 -0
  7. {cli2-2.7.0 → cli2-2.7.2}/README.rst +0 -0
  8. {cli2-2.7.0 → cli2-2.7.2}/classifiers.txt +0 -0
  9. {cli2-2.7.0 → cli2-2.7.2}/cli2/__init__.py +0 -0
  10. {cli2-2.7.0 → cli2-2.7.2}/cli2/argument.py +0 -0
  11. {cli2-2.7.0 → cli2-2.7.2}/cli2/cli.py +0 -0
  12. {cli2-2.7.0 → cli2-2.7.2}/cli2/colors.py +0 -0
  13. {cli2-2.7.0 → cli2-2.7.2}/cli2/decorators.py +0 -0
  14. {cli2-2.7.0 → cli2-2.7.2}/cli2/entry_point.py +0 -0
  15. {cli2-2.7.0 → cli2-2.7.2}/cli2/group.py +0 -0
  16. {cli2-2.7.0 → cli2-2.7.2}/cli2/node.py +0 -0
  17. {cli2-2.7.0 → cli2-2.7.2}/cli2/table.py +0 -0
  18. {cli2-2.7.0 → cli2-2.7.2}/cli2/test.py +0 -0
  19. {cli2-2.7.0 → cli2-2.7.2}/cli2/test_cli.py +0 -0
  20. {cli2-2.7.0 → cli2-2.7.2}/cli2/test_decorators.py +0 -0
  21. {cli2-2.7.0 → cli2-2.7.2}/cli2/test_entrypoint.py +0 -0
  22. {cli2-2.7.0 → cli2-2.7.2}/cli2/test_group.py +0 -0
  23. {cli2-2.7.0 → cli2-2.7.2}/cli2/test_inject.py +0 -0
  24. {cli2-2.7.0 → cli2-2.7.2}/cli2/test_node.py +0 -0
  25. {cli2-2.7.0 → cli2-2.7.2}/cli2/test_table.py +0 -0
  26. {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/SOURCES.txt +0 -0
  27. {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/dependency_links.txt +0 -0
  28. {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/entry_points.txt +0 -0
  29. {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/requires.txt +0 -0
  30. {cli2-2.7.0 → cli2-2.7.2}/cli2.egg-info/top_level.txt +0 -0
  31. {cli2-2.7.0 → cli2-2.7.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cli2
3
- Version: 2.7.0
3
+ Version: 2.7.2
4
4
  Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
5
  Home-page: https://yourlabs.io/oss/cli2
6
6
  Author: James Pic
@@ -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
- required = [
163
- arg
164
- for arg in self.values()
165
- if arg.default == inspect._empty
166
- and arg.param.name not in self.bound.kwargs
167
- and arg.param.kind not in (
168
- arg.param.VAR_KEYWORD,
169
- arg.param.VAR_POSITIONAL,
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 len(self.bound.args) < len(required):
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
- class TestCommand(Command):
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cli2
3
- Version: 2.7.0
3
+ Version: 2.7.2
4
4
  Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
5
  Home-page: https://yourlabs.io/oss/cli2
6
6
  Author: James Pic
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name='cli2',
6
- version='2.7.0',
6
+ version='2.7.2',
7
7
  setup_requires='setupmeta',
8
8
  install_requires=['docstring_parser'],
9
9
  extras_require=dict(
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