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
Hide --install-completion and --show-completion options without disabling autocompletion #498
Comments
And how do you manage completion then? How do you install the scripts and how do you call the program to get completion? |
We manage the installation of completion scripts, in the application itself. There's a bunch of things we manage in the application, including rc files, aws profiles, etc. So autocompletion becomes just another thing that we install automatically for the user. |
You can turn these options into a hidden command import sys
import typer
import typer.completion
from typer._completion_shared import Shells
app = typer.Typer(add_completion=False)
app_completion = typer.Typer(help="Generate and install completion scripts.", hidden=True)
app.add_typer(app_completion, name="completion")
@app_completion.command(no_args_is_help=True, help="Show completion for the specified shell, to copy or customize it.")
def show(ctx: typer.Context, shell: Shells) -> None:
typer.completion.show_callback(ctx, None, shell)
@app_completion.command(no_args_is_help=True, help="Install completion for the specified shell.")
def install(ctx: typer.Context, shell: Shells) -> None:
typer.completion.install_callback(ctx, None, shell)
def main():
typer.completion.completion_init()
sys.exit(app())
if __name__ == "__main__":
main()
|
Works for me! Thank you @antoinebrl |
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
First Check
Commit to Help
Example Code
Description
add_completion
either turns on or off autocompletion and the--install-completion
and--show-completion
options.To remove the options, you currently must set
add_completion=False
, which also disables autocompletion.I would like to decouple the two, and allow removing the options while still retaining the autocompletion capabilities.
We manage the autocompletion scripts in our application ourselves, without user input, and don't want the user to have access to these options.
Operating System
Linux, Windows, macOS
Operating System Details
No response
Typer Version
0.7.0
Python Version
Python 3.10.7
Additional Context
No response
The text was updated successfully, but these errors were encountered: