cli2 4.0.13__tar.gz → 4.0.15__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-4.0.13/cli2.egg-info → cli2-4.0.15}/PKG-INFO +1 -1
- cli2-4.0.15/cli2/ansible/pytest.py +10 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/client.py +54 -2
- {cli2-4.0.13 → cli2-4.0.15/cli2.egg-info}/PKG-INFO +1 -1
- {cli2-4.0.13 → cli2-4.0.15}/setup.py +1 -1
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_client.py +16 -0
- cli2-4.0.13/cli2/ansible/pytest.py +0 -7
- {cli2-4.0.13 → cli2-4.0.15}/MANIFEST.in +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/README.rst +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/classifiers.txt +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/__init__.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/ansible/__init__.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/ansible/action.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/ansible/playbook.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/ansible/variables.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/asyncio.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/cli.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/cli2.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/colors.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/configuration.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/decorators.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/display.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/__init__.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/client.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/conf.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/example.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/example_obj.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/nesting.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/obj.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/obj2.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/examples/test.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/lock.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/log.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/node.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/sphinx.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/table.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2/test.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2.egg-info/SOURCES.txt +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2.egg-info/dependency_links.txt +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2.egg-info/entry_points.txt +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2.egg-info/requires.txt +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/cli2.egg-info/top_level.txt +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/setup.cfg +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_ansible.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_ansible_variables.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_asyncio.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_cli.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_command.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_configuration.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_decorators.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_display.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_entry_point.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_group.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_inject.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_lock.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_node.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_restful.py +0 -0
- {cli2-4.0.13 → cli2-4.0.15}/tests/test_table.py +0 -0
|
@@ -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 =
|
|
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
|
"""
|
|
@@ -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']
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|