The typer command provides ✨ completion ✨ in the Terminal for your own small scripts. Even if they don't use Typer internally. Of course, it works better if you use Typer in your script.
It's probably most useful if you have a small custom Python script using Typer (maybe as part of some project), for some small tasks, and it's not complex/important enough to create a whole installable Python package for it (something to be installed with pip).
In that case, you can run your program with the typer command in your Terminal, and it will provide completion for your script.
The typer command also has functionality to generate Markdown documentation for your own Typer programs 📝.
There's nothing wrong with using Python directly to run it. And, in fact, if some other code or program uses your script, that would probably be the best way to do it.
⛔️ But in your terminal, you won't get completion when hitting TAB for any of the subcommands or options, like hello, bye, and --name.
Instead of using python directly you use the typer command.
After the name of the file, add the subcommand run.
✔️ If you installed completion for the typer command as described above, when you hit TAB you will have ✨ completion for everything ✨, including all the subcommands and options of your script, like hello, bye, and --name 🚀.
importtyperapp=typer.Typer(help="Awesome CLI user manager.")@app.command()defcreate(username:str):""" Create a new user with USERNAME. """print(f"Creating user: {username}")@app.command()defdelete(username:str,force:bool=typer.Option(...,prompt="Are you sure you want to delete the user?",help="Force deletion without confirmation.",),):""" Delete a user with USERNAME. If --force is not used, will ask for confirmation. """ifforce:print(f"Deleting user: {username}")else:print("Operation cancelled")@app.command()defdelete_all(force:bool=typer.Option(...,prompt="Are you sure you want to delete ALL users?",help="Force deletion without confirmation.",),):""" Delete ALL users in the database. If --force is not used, will ask for confirmation. """ifforce:print("Deleting all users")else:print("Operation cancelled")@app.command()definit():""" Initialize the users database. """print("Initializing user database")if__name__=="__main__":app()