-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Move short_help contents into docstrings #22016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
This PR does not modify any files shipped with the agent. To help streamline the release process, please consider adding the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
|
Docstrings serve a different purpose than I am ok with having the short help as the first line of the docstring, I am not sure if everyone is aware of it. The approach we seem to be following in ddev dep --help
Usage: ddev dep [OPTIONS] COMMAND [ARGS]...
Options:
-h, --help Show this message and exit.
Commands:
freeze Combine all dependencies for the Agent's static environment.
pin Pin a dependency for all checks that require it
sync Synchronize integration dependency spec with that of the agent...
updates Automatically check for dependency updatesThis is an example of how both work together in a The run command: #!/usr/bin/env python3
import click
@click.group()
def cli():
"""Main entry point for the example CLI."""
pass
@cli.command(short_help="Compact help text shown in list.")
def with_short_help():
"""
This is the full help text for the command.
It is much longer and explains details that you might not want
to clutter the main help output with.
When you run 'run --help', you will see the 'short_help' text.
When you run 'run with-short-help --help', you will see this text.
"""
click.echo("Running command with short_help defined.")
@cli.command()
def without_short_help():
"""
First line is treated as short help.
This is the rest of the docstring.
Since 'short_help' is not provided, click uses the first sentence or line
of the docstring for the listing in the parent command's help.
"""
click.echo("Running command without short_help defined.")
if __name__ == '__main__':
cli()Running help on run Running the other subcommands |
|
@AAraKKe so using the first line of the docstring as the short help text seems clearer to me. There's at least one place where we need the I see the point that people might start writing run-on short descriptions which won't fit, but I see the same danger with the I'd find it easier to pass on the knowledge that the docstring is one place for defining both short and long help messages. |
Yes, that is true. I am just saying that having the short help also printed when we run
We can also interpolate variables in the docstring, what is that case where we need it? EDIT: I just tested it and while we can interpolate in a docstring click does not seem to load the docstring as help anymore if interpolation is present. It seems that once we interpolate it the docstring does not behave as a "doc"string anymore and just as a multiline string. |
What does this PR do?
Motivation
Using
short_helpis not super idiomatic forclickand should be more deliberate.I'm starting to phase it out in favor of docstrings.