Description
First Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn't find it.
- I searched the Typer documentation, with the integrated search.
- I already searched in Google "How to X in Typer" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to Typer but to Click.
Commit to Help
- I commit to help with one of those options π
Example Code
from typing import Any, Callable
import typer
# Have typer.run() behave like:
def run(function: Callable[..., Any], add_completion: bool = False) -> Any:
app = typer.Typer(add_completion=add_completion)
app.command()(function)
app()
def main(name: str) -> None:
print(f"Hello, {name}!")
if __name__ == "__main__":
run(main) # defaults to suppressing completion installation 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.
Description
I thought I'd introduce Typer via some small scripts where argparse is unwieldy. But having the autocompletion options in the command help scared the absolute crap out of a number of people: they assumed I was overengineering, that it would be complicated. Luckily you can suppress those, as I discovered by reading the source.
(Working to bring the folks I scared around, because typer is an essential quality of life improvement for anyone using Python for pretty much anything.)
Wanted Solution
I'd like to see:
- add_completion default to False in typer.run. If you're doing the kind of program that warrants completion, you're probably using typer.Typer anyway.
- Some really minimal, sketchy documentation of the full API. There are other gems in there, eg, one thing people really liked that also isn't documented is no_args_is_help. People love that for ops scripts. Makes them feel safe. Come to think of it, I wish I could pass that to typer.run as well...
I understand (1) is a big change and not do be taken lightly, and as I discovered in my description of (2) it brings up whether you should be able to pass other Typer options via run. But the first thing I did when I fired up typer for the first time is wonder, "can I suppress those completion options," searched the docs, and found nothing, so (2) would have solved my problem.
I looked at main.py and run is simple as could be, so I could certainly make a PR for (1) if it's wanted. The instructions for contributing documentation look straightforward enough so I could take a crack at (2). That's a little more intimidating given the high standard of the documentation, but I could at least do a first draft.
Wanted Code
# in mycmd.py
typer.run(main)
# python mycmd.py --help
#
# *no completion options*
Alternatives
Minimally documenting the typer.Typer API. There's already an issue about documenting add_completion: #141, why not do all of 'em?
Operating System
macOS
Operating System Details
No response
Typer Version
0.4.1
Python Version
Python 3.10.2
Additional Context
No response