cli2 3.3.32__tar.gz → 3.3.33__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 (45) hide show
  1. {cli2-3.3.32/cli2.egg-info → cli2-3.3.33}/PKG-INFO +1 -1
  2. {cli2-3.3.32 → cli2-3.3.33}/cli2/client.py +5 -11
  3. {cli2-3.3.32 → cli2-3.3.33}/cli2/group.py +24 -10
  4. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_client.py +9 -0
  5. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_group.py +2 -2
  6. {cli2-3.3.32 → cli2-3.3.33/cli2.egg-info}/PKG-INFO +1 -1
  7. {cli2-3.3.32 → cli2-3.3.33}/setup.py +1 -1
  8. {cli2-3.3.32 → cli2-3.3.33}/MANIFEST.in +0 -0
  9. {cli2-3.3.32 → cli2-3.3.33}/README.rst +0 -0
  10. {cli2-3.3.32 → cli2-3.3.33}/classifiers.txt +0 -0
  11. {cli2-3.3.32 → cli2-3.3.33}/cli2/__init__.py +0 -0
  12. {cli2-3.3.32 → cli2-3.3.33}/cli2/argument.py +0 -0
  13. {cli2-3.3.32 → cli2-3.3.33}/cli2/asyncio.py +0 -0
  14. {cli2-3.3.32 → cli2-3.3.33}/cli2/cli.py +0 -0
  15. {cli2-3.3.32 → cli2-3.3.33}/cli2/colors.py +0 -0
  16. {cli2-3.3.32 → cli2-3.3.33}/cli2/command.py +0 -0
  17. {cli2-3.3.32 → cli2-3.3.33}/cli2/configuration.py +0 -0
  18. {cli2-3.3.32 → cli2-3.3.33}/cli2/decorators.py +0 -0
  19. {cli2-3.3.32 → cli2-3.3.33}/cli2/display.py +0 -0
  20. {cli2-3.3.32 → cli2-3.3.33}/cli2/entry_point.py +0 -0
  21. {cli2-3.3.32 → cli2-3.3.33}/cli2/example_client.py +0 -0
  22. {cli2-3.3.32 → cli2-3.3.33}/cli2/example_client_complex.py +0 -0
  23. {cli2-3.3.32 → cli2-3.3.33}/cli2/example_nesting.py +0 -0
  24. {cli2-3.3.32 → cli2-3.3.33}/cli2/example_obj.py +0 -0
  25. {cli2-3.3.32 → cli2-3.3.33}/cli2/logging.py +0 -0
  26. {cli2-3.3.32 → cli2-3.3.33}/cli2/node.py +0 -0
  27. {cli2-3.3.32 → cli2-3.3.33}/cli2/overrides.py +0 -0
  28. {cli2-3.3.32 → cli2-3.3.33}/cli2/sphinx.py +0 -0
  29. {cli2-3.3.32 → cli2-3.3.33}/cli2/table.py +0 -0
  30. {cli2-3.3.32 → cli2-3.3.33}/cli2/test.py +0 -0
  31. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_cli.py +0 -0
  32. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_command.py +0 -0
  33. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_configuration.py +0 -0
  34. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_decorators.py +0 -0
  35. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_display.py +0 -0
  36. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_entry_point.py +0 -0
  37. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_inject.py +0 -0
  38. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_node.py +0 -0
  39. {cli2-3.3.32 → cli2-3.3.33}/cli2/test_table.py +0 -0
  40. {cli2-3.3.32 → cli2-3.3.33}/cli2.egg-info/SOURCES.txt +0 -0
  41. {cli2-3.3.32 → cli2-3.3.33}/cli2.egg-info/dependency_links.txt +0 -0
  42. {cli2-3.3.32 → cli2-3.3.33}/cli2.egg-info/entry_points.txt +0 -0
  43. {cli2-3.3.32 → cli2-3.3.33}/cli2.egg-info/requires.txt +0 -0
  44. {cli2-3.3.32 → cli2-3.3.33}/cli2.egg-info/top_level.txt +0 -0
  45. {cli2-3.3.32 → cli2-3.3.33}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cli2
3
- Version: 3.3.32
3
+ Version: 3.3.33
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
@@ -700,13 +700,7 @@ class ModelGroup(Group):
700
700
  dict(model=cls),
701
701
  )
702
702
  )
703
-
704
- url_list_methods = ['find', 'get', 'delete', 'create']
705
- if cls.url_list:
706
- for name in url_list_methods:
707
- self.cmd(getattr(cls, name))
708
-
709
- self.load_cls(cls, exclude=url_list_methods)
703
+ self.load_cls(cls)
710
704
 
711
705
 
712
706
  class ModelMetaclass(type):
@@ -820,7 +814,7 @@ class Model(metaclass=ModelMetaclass):
820
814
 
821
815
  @classmethod
822
816
  @hide('expressions')
823
- @cmd(color='green')
817
+ @cmd(color='green', condition=lambda cls: cls.url_list)
824
818
  def find(cls, *expressions, **params):
825
819
  """
826
820
  Find objects filtered by GET params
@@ -874,7 +868,7 @@ class Model(metaclass=ModelMetaclass):
874
868
  raise Exception(f'{type(self).__name__}.url_list not set')
875
869
  return self.url_detail.format(self=self)
876
870
 
877
- @cmd(color='red')
871
+ @cmd(color='red', condition=lambda cls: cls.url_list)
878
872
  async def delete(self):
879
873
  """
880
874
  Delete model.
@@ -884,7 +878,7 @@ class Model(metaclass=ModelMetaclass):
884
878
  return await self.client.delete(self.url)
885
879
 
886
880
  @classmethod
887
- @cmd(doc="""
881
+ @cmd(condition=lambda cls: cls.url_list, doc="""
888
882
  POST request to create.
889
883
 
890
884
  Example:
@@ -900,7 +894,7 @@ class Model(metaclass=ModelMetaclass):
900
894
  return obj
901
895
 
902
896
  @classmethod
903
- @cmd(color='green', doc="""
897
+ @cmd(color='green', condition=lambda cls: cls.url_list, doc="""
904
898
  Get a model based on kwargs.
905
899
 
906
900
  Example:
@@ -177,21 +177,35 @@ class Group(EntryPoint, dict):
177
177
  self.group(name).load(target, parent=obj)
178
178
  return self
179
179
 
180
- def load_cls(self, cls, exclude=None):
180
+ def load_cls(self, cls, leaf=None):
181
181
  """
182
182
  Load all methods which have been decorated with @cmd
183
+
184
+ Note that you can define conditions, this is how we hide functions such
185
+ as create/delete/get from models without url_list:
186
+
187
+ .. code-block:: python
188
+
189
+ @cli2.cmd(condition=lambda cls: cls.url_list)
183
190
  """
184
- exclude = exclude or []
191
+ leaf = leaf if leaf else cls
192
+ for base in cls.__bases__:
193
+ self.load_cls(base, leaf=leaf)
194
+
185
195
  for name, method in cls.__dict__.items():
186
- if name in exclude:
187
- continue
188
196
  wrapped_method = getattr(method, '__func__', None)
189
- if hasattr(wrapped_method, 'cli2'):
190
- self.cmd(wrapped_method)
191
- elif hasattr(method, 'cli2'):
192
- self.cmd(method)
193
- for base in cls.__bases__:
194
- self.load_cls(base, exclude=exclude)
197
+ cfg = getattr(
198
+ wrapped_method,
199
+ 'cli2',
200
+ getattr(method, 'cli2', None),
201
+ )
202
+ if cfg is None:
203
+ continue
204
+ condition = cfg.get('condition', None)
205
+ if condition:
206
+ if not condition(leaf):
207
+ continue
208
+ self.cmd(method)
195
209
 
196
210
  def __call__(self, *argv):
197
211
  self.exit_code = 0
@@ -68,6 +68,15 @@ async def test_client_cli_override(client_class, httpx_mock):
68
68
  return cls.url_list
69
69
  assert await Client.cli['testmodel']['find'].async_call('bar') == 'bar/foo'
70
70
 
71
+ class TestModel2(Client.Model):
72
+ @classmethod
73
+ @cli2.cmd
74
+ async def find(cls):
75
+ return 'foo'
76
+
77
+ assert await Client.cli['testmodel2']['find'].async_call() == 'foo'
78
+ assert 'get' not in Client.cli['testmodel2']
79
+
71
80
 
72
81
  def test_client_model(client_class):
73
82
  assert issubclass(client_class.Model, cli2.Model)
@@ -225,11 +225,11 @@ def test_load_cls():
225
225
  def test2(self):
226
226
  pass
227
227
 
228
- @cli2.cmd
228
+ @cli2.cmd(condition=lambda cls: False)
229
229
  def exclude(self):
230
230
  pass
231
231
  group = Group()
232
- group.load_cls(Foo, exclude=['exclude'])
232
+ group.load_cls(Foo)
233
233
  assert 'bar' not in group
234
234
  assert 'test' in group
235
235
  assert 'test2' in group
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cli2
3
- Version: 3.3.32
3
+ Version: 3.3.33
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='3.3.32',
6
+ version='3.3.33',
7
7
  setup_requires='setupmeta',
8
8
  install_requires=[
9
9
  'docstring_parser',
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
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