From: Kefu Chai Date: Sat, 26 Dec 2020 14:15:33 +0000 (+0800) Subject: pybind/mgr: translate argspec to argdesc X-Git-Tag: v16.1.0~20^2~24 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4053413569138b9d936a7eeb68cb82bc3f52e11d;p=ceph.git pybind/mgr: translate argspec to argdesc Signed-off-by: Kefu Chai --- diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 9b8235d8cdc9..aa4699cacca1 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -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