attzonko / mmpy_bot

A python-based chatbot for Mattermost (http://www.mattermost.org).
MIT License
265 stars 104 forks source link

Duplicate content in click command help output #362

Open sw-dbrown opened 1 year ago

sw-dbrown commented 1 year ago

Describe the bug

The output of help for commands created with click contains duplicate content and is sometimes oddly formatted.

How To Reproduce

Create a bot with the following listener:

@listen_to("dummy")
@click.command(
    context_settings=dict(
        allow_extra_args=True,
    ),
)
@click.option(
    "-o",
    "--opt",
    type=str,
    help="Help text for option",
)
@click.argument("args", nargs=-1)
def dummy(
    self,
    message,
    opt: str,
    args: List[str],
) -> None:
    """A description of the command

    More information here
    """

    return

Send the message dummy --help. This leads to the following (correct) output on the CLI of the bot:

Usage: MyPlugin [OPTIONS] [ARGS]...

  A description of the command

  More information here

Options:
  -o, --opt TEXT  Help text for option
  --help          Show this message and exit.

However, in Mattermost the following response is sent:

image

Expected behavior

The help text defined in the docstring should only be shown once and formatted consistently (ie. not mixing regular and verbatim text)

Operating Environment (please complete the following information):

Additional context

-

unode commented 1 year ago

Editing my previous comment...

We may be doing the docstring handling twice.

Possibly the cause is:

https://github.com/attzonko/mmpy_bot/blob/f726ebe5a456932da408be173b2f1f511d9d33a8/mmpy_bot/function.py#L113

where we append the content to the docstring. If previously already added it would be added twice. Needs further testing but I don't currently have the time to dig into it.

Thanks for reporting