Skip to content

HelpFormatter#7

Merged
swedgwood merged 14 commits intomasterfrom
help-formatter
Feb 13, 2018
Merged

HelpFormatter#7
swedgwood merged 14 commits intomasterfrom
help-formatter

Conversation

@swedgwood
Copy link
Copy Markdown
Contributor

image
image
image
Added new HelpFormatter, for a more python-y looking help command.
Features:

  • Help code block formatted as python

  • Cogs appear as classes

  • Command helptext shows as comments

  • Ending note for help command shows as comments

  • Getting help for an individual cog still works

  • Getting help on a specific commands shows a mock definition of said command with helptext as it's docstring, and its arguments shown as the arguments to the function with added type hinting.

Comment thread bot/formatter.py Outdated
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# basically the same function but changed:
Copy link
Copy Markdown
Contributor

@AkiraSama AkiraSama Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not essential, but these comments could be docstrings

Copy link
Copy Markdown
Contributor

@lemonsaurus lemonsaurus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all this is excellent work. The output looks phenomenal.

Comment thread bot/formatter.py Outdated
# basically the same function but changed:
# - to make the helptext appear as a comment
# - to change the indentation to the PEP8 standard: 4 spaces
def _add_subcommands_to_page(self, max_width, commands):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type annotations?

Comment thread bot/formatter.py
def _add_subcommands_to_page(self, max_width, commands):
for name, command in commands:
if name in command.aliases:
# skip aliases
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably self explanatory.

Comment thread bot/formatter.py
# """
# await do_<command>(ctx, <args>)

# strip the command of bot. and ()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block (from here and until the return) generally feels too dense. PEP8 allows blank lines used sparingly to split code into logical sections, and this can be a real gift for good readability. personally I try to write comments that encapsulate the actions of at least 3-4 lines of code and then put blank lines before the comments.

I also try to make sure similar things are grouped together, and that similar actions are handled consistently. the comments should also apply the same tense (don't mix present tense and past tense). applying that philosophy to this section, I'd do something like this;

# strip the command of bot. and ()
stripped_command = self.command.name.replace(HELP_PREFIX, "").replace("()", "")

# get the args using the handy inspect module
argspec = getfullargspec(self.command.callback)
arguments = formatargspec(*argspec)
args_no_type_hints = ", ".join(argspec[0])

# remove self from the args
arguments = arguments.replace("self, ", "")
args_no_type_hints = args_no_type_hints.replace("self, ", "")

# 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})"
self._paginator.add_line(definition)
self._paginator.add_line(docstring)
self._paginator.add_line(invocation)

return self._paginator.pages

Comment thread bot/formatter.py Outdated
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def _add_subcommands_to_page(self, max_width, commands):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type annotations?

Copy link
Copy Markdown
Contributor

@lemonsaurus lemonsaurus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great now.

Comment thread bot/formatter.py
@@ -0,0 +1,102 @@
# coding=utf-8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this blank line is, I believe, against the law

@swedgwood swedgwood merged commit 1c26f48 into master Feb 13, 2018
@swedgwood swedgwood deleted the help-formatter branch February 13, 2018 19:40
Ultros-Bot pushed a commit that referenced this pull request Sep 26, 2018
Add tag image support.

Closes #7

See merge request python-discord/projects/bot!18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants