mkdocs / mkdocs-click

An MkDocs extension to generate documentation for Click command line applications
https://pypi.org/project/mkdocs-click
Apache License 2.0
109 stars 15 forks source link

Underscore becomes hyphen in usage #9

Closed valpesendorfer closed 3 years ago

valpesendorfer commented 3 years ago

When generating the automatic documentation for a click command that has an underscore in its name, the underscore becomes a hyphen in the "Usage" section.

Example:

Using the example from README, just renaming cli to cli_test renders to:

image

florimondmanca commented 3 years ago

@valpesendorfer Hello!

The usage is rendered directly from Click, and in particular for the command name we use Click's command.name. As you can see below it transforms underscores into hyphens:

import click

@click.command()
def cli_test():
    pass

print(cli_test.name)  # "cli-test"

As an alternative, we could consider using command.callback.__name__. But then explicit name set on commands wouldn't be honored, and that would be a proper bug. Our best bet to stick to Click's behavior as closely as we can.

So if you'd like the Usage: ... to show cli_test [OPTIONS] ..., then you might want to consider doing:

@click.command(name="cli_test")
def cli_test():
    pass

I'd agree that looks kind of funky, but that's just how Click treats command names… You could consider digging into issues on the click repo to see if there's anyone who suggested changing that behavior.

For now, since we have a workaround and it doesn't seem to really be on us, I'll close this for now. Thanks. :-)