[X] I added a very descriptive title to this issue.
[X] I used the GitHub search to find a similar issue and didn't find it.
[X] I searched the Typer documentation, with the integrated search.
[X] I already searched in Google "How to X in Typer" and didn't find any information.
[X] I already read and followed all the tutorial in the docs and didn't find an answer.
[X] I already checked if it is not related to Typer but to Click.
Commit to Help
[X] I commit to help with one of those options 👆
Example Code
"""MyProgram
This program does this and that.
"""
import typer
app = typer.Typer(help=__doc__)
@app.command()
def main():
print("Hello, World!")
if __name__ == "__main__":
app()
"""
$ python main.py --help
Usage: main.py [OPTIONS]
Options:
--install-completion [bash|zsh|fish|powershell|pwsh]
Install completion for the specified shell.
--show-completion [bash|zsh|fish|powershell|pwsh]
Show completion for the specified shell, to
copy it or customize the installation.
--help Show this message and exit.
"""
Description
Currently, if you have docstring on main(), the help argument in Typer() is ignored.
This feature is useful when you want both the CLI help pages to come from the module docstring.
Wanted Solution
Always show the help string in Typer(help=...). Either
Ignore the docstring in main.
The Typer help goes first then the main docstring.
Wanted Code
"""MyProgram
This program does this and that.
"""
import typer
app = typer.Typer(help=__doc__)
@app.command()
def main():
print("Hello, World!")
if __name__ == "__main__":
app()
"""
$ python main.py --help
Usage: main.py [OPTIONS]
MyProgram
This program does this and that.
Options:
--install-completion [bash|zsh|fish|powershell|pwsh]
Install completion for the specified shell.
--show-completion [bash|zsh|fish|powershell|pwsh]
Show completion for the specified shell, to
copy it or customize the installation.
--help Show this message and exit.
"""
Alternatives
Unfortunately this does not work.
"""MyProgram
This program does this and that.
"""
import typer
def main():
f"""{__doc__}"""
print("Hello, World!")
if __name__ == "__main__":
typer.run(main)
I've found a workaround. It isn't ugly, but it is more boilerplate:
"""MyProgram
This program does this and that.
"""
import typer
def main():
f"""{__doc__}"""
print("Hello, World!")
if __name__ == "__main__":
main.__doc__ = __doc__
typer.run(main)
First Check
Commit to Help
Example Code
Description
Currently, if you have docstring on
main()
, the help argument inTyper()
is ignored.This feature is useful when you want both the CLI help pages to come from the module docstring.
Wanted Solution
Always show the help string in
Typer(help=...)
. EitherWanted Code
Alternatives
Unfortunately this does not work.
Operating System
Linux, macOS
Operating System Details
No response
Typer Version
0.4.0
Python Version
Python 3.9.6
Additional Context
No response