diff options
| author | 2018-02-21 23:12:46 +0000 | |
|---|---|---|
| committer | 2018-02-21 23:12:46 +0000 | |
| commit | c99fd71af3f754565d8942304acf699c2c3dba60 (patch) | |
| tree | a160d13ecd275beb505c22c2c45e65d1cbfe62ba | |
| parent | Clickup commands #z20f (#10) (diff) | |
Fixed formatter.py #1rhpq
- fixed multiline docstrings
- added newline after docstring
- changed full modulename.classname in type hints to only classname
- fixed the format of the arguments to do_<command>
| -rw-r--r-- | bot/formatter.py | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/bot/formatter.py b/bot/formatter.py index 503ae331d..cb7c99b88 100644 --- a/bot/formatter.py +++ b/bot/formatter.py @@ -61,16 +61,37 @@ class Formatter(HelpFormatter): # get the args using the handy inspect module argspec = getfullargspec(self.command.callback) arguments = formatargspec(*argspec) - args_no_type_hints = ", ".join(argspec[0]) + for arg, annotation in argspec.annotations.items(): + # remove module name to only show class name + # discord.ext.commands.context.Context -> Context + arguments = arguments.replace(f"{annotation.__module__}.", "") + + # manipulate the argspec to make it valid python when 'calling' the do_<command> + args_no_type_hints = argspec.args + for kwarg in argspec.kwonlyargs: + args_no_type_hints.append("{0}={0}".format(kwarg)) + args_no_type_hints = "({0})".format(", ".join(args_no_type_hints)) # remove self from the args arguments = arguments.replace("self, ", "") args_no_type_hints = args_no_type_hints.replace("self, ", "") + # indent every line in the help message + helptext = "\n ".join(self.command.help.split("\n")) + # prepare the different sections of the help output, and add them to the paginator definition = f"async def {stripped_command}{arguments}:" - docstring = f" \"\"\"\n {self.command.help}\n \"\"\"" - invocation = f" await do_{stripped_command}({args_no_type_hints})" + doc_elems = [ + '"""', + helptext, + '"""' + ] + + docstring = "" + for elem in doc_elems: + docstring += f' {elem}\n' + + invocation = f" await do_{stripped_command}{args_no_type_hints}" self._paginator.add_line(definition) self._paginator.add_line(docstring) self._paginator.add_line(invocation) |