cli2 4.0.12__tar.gz → 4.0.14__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 (57) hide show
  1. {cli2-4.0.12/cli2.egg-info → cli2-4.0.14}/PKG-INFO +1 -1
  2. {cli2-4.0.12 → cli2-4.0.14}/cli2/cli.py +6 -0
  3. {cli2-4.0.12 → cli2-4.0.14}/cli2/client.py +54 -2
  4. {cli2-4.0.12 → cli2-4.0.14/cli2.egg-info}/PKG-INFO +1 -1
  5. {cli2-4.0.12 → cli2-4.0.14}/setup.py +1 -1
  6. {cli2-4.0.12 → cli2-4.0.14}/tests/test_client.py +16 -0
  7. {cli2-4.0.12 → cli2-4.0.14}/tests/test_command.py +12 -0
  8. {cli2-4.0.12 → cli2-4.0.14}/MANIFEST.in +0 -0
  9. {cli2-4.0.12 → cli2-4.0.14}/README.rst +0 -0
  10. {cli2-4.0.12 → cli2-4.0.14}/classifiers.txt +0 -0
  11. {cli2-4.0.12 → cli2-4.0.14}/cli2/__init__.py +0 -0
  12. {cli2-4.0.12 → cli2-4.0.14}/cli2/ansible/__init__.py +0 -0
  13. {cli2-4.0.12 → cli2-4.0.14}/cli2/ansible/action.py +0 -0
  14. {cli2-4.0.12 → cli2-4.0.14}/cli2/ansible/playbook.py +0 -0
  15. {cli2-4.0.12 → cli2-4.0.14}/cli2/ansible/pytest.py +0 -0
  16. {cli2-4.0.12 → cli2-4.0.14}/cli2/ansible/variables.py +0 -0
  17. {cli2-4.0.12 → cli2-4.0.14}/cli2/asyncio.py +0 -0
  18. {cli2-4.0.12 → cli2-4.0.14}/cli2/cli2.py +0 -0
  19. {cli2-4.0.12 → cli2-4.0.14}/cli2/colors.py +0 -0
  20. {cli2-4.0.12 → cli2-4.0.14}/cli2/configuration.py +0 -0
  21. {cli2-4.0.12 → cli2-4.0.14}/cli2/decorators.py +0 -0
  22. {cli2-4.0.12 → cli2-4.0.14}/cli2/display.py +0 -0
  23. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/__init__.py +0 -0
  24. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/client.py +0 -0
  25. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/conf.py +0 -0
  26. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/example.py +0 -0
  27. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/example_obj.py +0 -0
  28. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/nesting.py +0 -0
  29. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/obj.py +0 -0
  30. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/obj2.py +0 -0
  31. {cli2-4.0.12 → cli2-4.0.14}/cli2/examples/test.py +0 -0
  32. {cli2-4.0.12 → cli2-4.0.14}/cli2/lock.py +0 -0
  33. {cli2-4.0.12 → cli2-4.0.14}/cli2/log.py +0 -0
  34. {cli2-4.0.12 → cli2-4.0.14}/cli2/node.py +0 -0
  35. {cli2-4.0.12 → cli2-4.0.14}/cli2/sphinx.py +0 -0
  36. {cli2-4.0.12 → cli2-4.0.14}/cli2/table.py +0 -0
  37. {cli2-4.0.12 → cli2-4.0.14}/cli2/test.py +0 -0
  38. {cli2-4.0.12 → cli2-4.0.14}/cli2.egg-info/SOURCES.txt +0 -0
  39. {cli2-4.0.12 → cli2-4.0.14}/cli2.egg-info/dependency_links.txt +0 -0
  40. {cli2-4.0.12 → cli2-4.0.14}/cli2.egg-info/entry_points.txt +0 -0
  41. {cli2-4.0.12 → cli2-4.0.14}/cli2.egg-info/requires.txt +0 -0
  42. {cli2-4.0.12 → cli2-4.0.14}/cli2.egg-info/top_level.txt +0 -0
  43. {cli2-4.0.12 → cli2-4.0.14}/setup.cfg +0 -0
  44. {cli2-4.0.12 → cli2-4.0.14}/tests/test_ansible.py +0 -0
  45. {cli2-4.0.12 → cli2-4.0.14}/tests/test_ansible_variables.py +0 -0
  46. {cli2-4.0.12 → cli2-4.0.14}/tests/test_asyncio.py +0 -0
  47. {cli2-4.0.12 → cli2-4.0.14}/tests/test_cli.py +0 -0
  48. {cli2-4.0.12 → cli2-4.0.14}/tests/test_configuration.py +0 -0
  49. {cli2-4.0.12 → cli2-4.0.14}/tests/test_decorators.py +0 -0
  50. {cli2-4.0.12 → cli2-4.0.14}/tests/test_display.py +0 -0
  51. {cli2-4.0.12 → cli2-4.0.14}/tests/test_entry_point.py +0 -0
  52. {cli2-4.0.12 → cli2-4.0.14}/tests/test_group.py +0 -0
  53. {cli2-4.0.12 → cli2-4.0.14}/tests/test_inject.py +0 -0
  54. {cli2-4.0.12 → cli2-4.0.14}/tests/test_lock.py +0 -0
  55. {cli2-4.0.12 → cli2-4.0.14}/tests/test_node.py +0 -0
  56. {cli2-4.0.12 → cli2-4.0.14}/tests/test_restful.py +0 -0
  57. {cli2-4.0.12 → cli2-4.0.14}/tests/test_table.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cli2
3
- Version: 4.0.12
3
+ Version: 4.0.14
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
@@ -1161,6 +1161,9 @@ class Argument:
1161
1161
  command object.
1162
1162
 
1163
1163
  If the factory function takes an `arg` argument, it will pass self.
1164
+
1165
+ It will forward any argument to the factory function if detected in
1166
+ it's signature.
1164
1167
  """
1165
1168
  kwargs = dict()
1166
1169
  sig = inspect.signature(self.factory)
@@ -1168,4 +1171,7 @@ class Argument:
1168
1171
  kwargs['cmd'] = self.cmd
1169
1172
  if 'arg' in sig.parameters:
1170
1173
  kwargs['arg'] = self
1174
+ for key, arg in self.cmd.items():
1175
+ if key in sig.parameters:
1176
+ kwargs[key] = arg.value
1171
1177
  return self.factory(**kwargs)
@@ -699,6 +699,11 @@ class ModelMetaclass(type):
699
699
  attributes['paginator'] = attributes['Paginator']
700
700
 
701
701
  cls = super().__new__(cls, name, bases, attributes)
702
+ cls.Command = type(
703
+ 'ModelCommand',
704
+ (cls.Command,),
705
+ dict(model=cls),
706
+ )
702
707
  client = getattr(cls, 'client', None)
703
708
  if client:
704
709
  if not cls.paginator:
@@ -733,6 +738,19 @@ class ModelMetaclass(type):
733
738
 
734
739
  return cls
735
740
 
741
+ @property
742
+ def cli(cls):
743
+ if '_cli' not in cls.__dict__:
744
+ cli_kwargs = dict(
745
+ name=cls.__name__.lower(),
746
+ doc=inspect.getdoc(cls),
747
+ cmdclass=cls.Command,
748
+ )
749
+ cli_kwargs.update(cls.cli_kwargs)
750
+ cls._cli = Group(**cli_kwargs)
751
+ cls._cli.load(cls)
752
+ return cls._cli
753
+
736
754
 
737
755
  class Model(metaclass=ModelMetaclass):
738
756
  """
@@ -765,13 +783,29 @@ class Model(metaclass=ModelMetaclass):
765
783
  .. py:attribute:: url
766
784
 
767
785
  Object URL based on :py:attr:`url_detail` and :py:attr:`id_field`.
786
+
787
+ .. py:attribute:: cli_kwargs
788
+
789
+ Dict of kwargs to use to create the :py:class:`~cli2.cli.Group` for
790
+ this model.
791
+
792
+ .. py:attribute:: Command
793
+
794
+ Define a Command class inside the ModelClass to use a specific
795
+ :py:class:`~cli2.cli.Command` class for a model.
796
+ Don't inherit from anything: a new class will be generated for you
797
+ inheriting from both :py:class:`~cls.cli2.client.ModelCommand` and
798
+ :py:attr:`~cli2.cli.Client.Command`.
768
799
  """
769
800
  paginator = None
770
801
  model_command = ModelCommand
771
- model_group = ModelGroup
772
802
  url_list = None
773
803
  url_detail = '{self.url_list}/{self.id_value}'
774
804
  id_field = 'id'
805
+ cli_kwargs = dict()
806
+
807
+ class Command(ModelCommand):
808
+ pass
775
809
 
776
810
  def __init__(self, data=None, **values):
777
811
  """
@@ -947,8 +981,15 @@ class ClientMetaclass(type):
947
981
  def __new__(cls, name, bases, attributes):
948
982
  if 'Paginator' in attributes:
949
983
  attributes['paginator'] = attributes['Paginator']
984
+
950
985
  cls = super().__new__(cls, name, bases, attributes)
951
986
 
987
+ cls.Command = type(
988
+ 'ClientCommand',
989
+ (cls.Command, Command),
990
+ dict(),
991
+ )
992
+
952
993
  # bind ourself as _client_class to any inherited model
953
994
  cls.Model = type('Model', (Model,), dict(_client_class=cls))
954
995
  cls.models = []
@@ -964,12 +1005,13 @@ class ClientMetaclass(type):
964
1005
  cls=dict(factory=lambda: cls),
965
1006
  self=dict(factory=lambda: cls())
966
1007
  ),
1008
+ cmdclass=cls.Command,
967
1009
  )
968
1010
  cli_kwargs.update(cls.cli_kwargs)
969
1011
  cli = Group(**cli_kwargs)
970
1012
  cli.load(cls)
971
1013
  for model in cls.models:
972
- group = ModelGroup(model)
1014
+ group = model.cli
973
1015
  if len(group) > 1:
974
1016
  cli[model.__name__.lower()] = group
975
1017
  cls._cli = cli
@@ -1236,6 +1278,13 @@ class Client(metaclass=ClientMetaclass):
1236
1278
  class YourClient(cli2.Client):
1237
1279
  cli_kwargs = dict(cmdclass=YourCommandClass)
1238
1280
 
1281
+ .. py:attribute:: Command
1282
+
1283
+ Define a Command class inside the Client class to use a specific
1284
+ :py:class:`~cli2.cli.Command` class for a model.
1285
+ Don't inherit from anything: a new class will be generated for you
1286
+ inheriting from :py:attr:`~cli2.cli.Client.Command` for you.
1287
+
1239
1288
  .. py:attribute:: debug
1240
1289
 
1241
1290
  Enforce full logging: quiet requests are logged, masking does not
@@ -1251,6 +1300,9 @@ class Client(metaclass=ClientMetaclass):
1251
1300
  mask = []
1252
1301
  debug = False
1253
1302
 
1303
+ class Command:
1304
+ pass
1305
+
1254
1306
  def __init__(self, *args, handler=None, semaphore=None, mask=None,
1255
1307
  debug=False, **kwargs):
1256
1308
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cli2
3
- Version: 4.0.12
3
+ Version: 4.0.14
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='4.0.12',
6
+ version='4.0.14',
7
7
  setup_requires='setupmeta',
8
8
  install_requires=[
9
9
  'docstring_parser',
@@ -1145,3 +1145,19 @@ async def test_client_token_apply(client_class, httpx_mock):
1145
1145
  await client.client_reset()
1146
1146
  assert client.token == 2
1147
1147
  assert client.client.token == 2
1148
+
1149
+
1150
+ def test_client_command(client_class):
1151
+ class Client(client_class):
1152
+ class Command(cli2.Command):
1153
+ pass
1154
+
1155
+ class Model(Client.Model):
1156
+ url_list = '/foo'
1157
+ class Command(Client.Command, cli2.Model.Command):
1158
+ pass
1159
+
1160
+ assert issubclass(Client.cli.cmdclass, Client.Command)
1161
+ assert issubclass(Client.cli['model'].cmdclass, Client.Command)
1162
+ assert issubclass(Client.cli['model'].cmdclass, cli2.Model.Command)
1163
+ assert 'get' in Client.cli['model']
@@ -707,3 +707,15 @@ def test_keyboard_interrupt_async():
707
707
  cmd()
708
708
  assert cmd.exit_code == 1
709
709
  assert cmd.post_result == 'foo'
710
+
711
+
712
+ def test_factory_value_args():
713
+ def myfactory(foo):
714
+ return foo
715
+
716
+ @cli2.arg('bar', factory=myfactory)
717
+ def mycmd(foo, bar):
718
+ return foo
719
+
720
+ cmd = cli2.Command(mycmd)
721
+ assert cmd('a') == 'a'
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
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