]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/mgr: translate argspec to argdesc
authorKefu Chai <kchai@redhat.com>
Sat, 26 Dec 2020 14:15:33 +0000 (22:15 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 14 Jan 2021 14:08:35 +0000 (22:08 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/mgr_module.py

index 9b8235d8cdc9201c3098736c0da7aa232e19d925..aa4699cacca1a7afea3945850f408370299fd14c 100644 (file)
@@ -311,6 +311,8 @@ class CLICommand(object):
         self.arg_spec = {}    # type: Dict[str, Any]
         self.first_default = -1
 
+    KNOWN_ARGS = '_', 'self', 'mgr', 'inbuf', 'return'
+
     @staticmethod
     def _parse_args(args):
         if not args:
@@ -332,7 +334,14 @@ class CLICommand(object):
         if not self.desc:
             self.desc = inspect.getdoc(func)
         if not self.args_dict:
-            self.arg_spec = inspect.getfullargspec(func).annotations
+            full_argspec = inspect.getfullargspec(func)
+            self.arg_spec = full_argspec.annotations
+            for arg in full_argspec.args:
+                assert arg in CLICommand.KNOWN_ARGS or arg in self.arg_spec, \
+                    f"'{arg}' is not annotated for {func}: {full_argspec}"
+            self.args = ' '.join(CephArgtype.to_argdesc(tp, dict(name=name))
+                                 for name, tp in self.arg_spec)
+
         self.COMMANDS[self.prefix] = self
         return self.func