From 4053413569138b9d936a7eeb68cb82bc3f52e11d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 26 Dec 2020 22:15:33 +0800 Subject: [PATCH] pybind/mgr: translate argspec to argdesc Signed-off-by: Kefu Chai --- src/pybind/mgr/mgr_module.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 9b8235d8cdc..aa4699cacca 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 -- 2.39.5