Repository navigation
Need a built-in way to specify how to extract help text from docstring #1976
First Check
Example Codeimport typer
app = typer.Typer()
@app.command()
def run(things: list[str]) -> None:
"""
Execute some things.
:param things: List of things to execute
:return: None
"""
pass
if __name__ == "__main__":
app()DescriptionRefer to the Example Code I documented the function in reST-style, so parameters are listed under the description with However, if i run the program, for example: I'd appreciate it if we can make @app.command(help=DocstringSyntax.reST) # DocstringSyntax is an enum
def run(...):
...or def docstring_cleanup(docstring: str | None) -> str:
# Typer should invoke this callback function with the str from inspect.getdoc(func)
if not docstring:
return ""
paras = [p.strip() for p in docstring.strip().split("\n\n") if p.strip()]
return paras[0] if paras else ""
@app.command(help=docstring_cleanup)
def run(...):
...In either case, Typer would extract only the first paragraph, thus invoking help would look like this: Operating SystemLinux, Windows, Other Operating System DetailsCurrently developing in Windows, but the tool will be running on Linux Project Version0.27.2 Python Version3.14.8 Additional ContextNo response |
Replies: 1 comment
|
You can use a "form feed" character ( @app.command()
def run(things: list[str]) -> None:
"""
Execute some things.
\f
:param things: List of things to execute
:return: None
"""It seems that it's not documented in Typer's docs, but it works. |
You can use a "form feed" character (
\f) to achieve this:It seems that it's not documented in Typer's docs, but it works.
Read about it in FastAPI's docs: https://fastapi.tiangolo.com/advanced/path-operation-advanced-configuration/#advanced-description-from-docstring