:memo: Update docs with references to --install-completion
Before adoption: this commit came in with the history the project adopted, so no landing records it.
and use subcommand everywhere instead of sub-command for consistency with Click
authored by Sebastián Ramírez · committed by Sebastián Ramírez · parent f192d9d · Browse files · 4 files·+54 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+54 added−23 removed
- other:+54 added−23 removed
Provenance
- Commit
c941db5- Tree
c5c129f- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
Sebastián Ramírez <tiangolo@gmail.com>- Parent
f192d9d
4 files changed+54 added−23 removed
modified:docs/tutorial/index.md+20 added-4 removed
35 unmodified lines36373839404140414243444546474849505152535455565758596061626364656667565768697071727374757635 unmodified linesAll the code blocks can be copied and used directly (they are tested Python files).
To run any of the examples, copy the code to a file `main.py`, and run it:
<div class="termy">
```bashpython main.py```console$ python main.py
✨ The magic happens here ✨```
</div>
It is **HIGHLY encouraged** that you write or copy the code, edit it and run it locally.
Using it in your editor is what really shows you the benefits of Typer, seeing how little code you have to write, all the type checks, autocompletion, etc.
And running the examples is what will really help you understand what is going on.
You can learn a lot more by running some examples and playing around with them than by reading all the docs here.
---
## Install Typer
The first step is to install Typer.
For the tutorial, you might want to install it with all the optional dependencies and features:
<div class="termy">
```bashpip install typer[all]```console$ pip install typer[all]---> 100%Successfully installed typer click colorama click-completion```
</div>
...that also includes `colorama` and `click-completion`.modified:docs/features.md+6 added-3 removed
41 unmodified lines42434445464746474849505152535454555657585960616215 unmodified lines41 unmodified lines
The resulting CLI apps created with **Typer** have the nice features of many "pro" command line programs you probably already love.
* Automatic help commands and options.* Automatic command and sub-command structure handling (you will see more about sub-commands in the Tutorial - User Guide).* Automatic autocompletion for the CLI app in all operating systems, in all the shells (Bash, Zsh, Fish, PowerShell), so that the final user of your app can just hit <kbd>TAB</kbd> and get the options of sub-commands. ** Automatic command and subcommand structure handling (you will see more about subcommands in the Tutorial - User Guide).* Automatic autocompletion for the CLI app in all operating systems, in all the shells (Bash, Zsh, Fish, PowerShell), so that the final user of your app can just hit <kbd>TAB</kbd> and get the available options or subcommands. *
!!! note "* Autocompletion" For the autocompletion to work on all shells you also need to add the dependency `click-completion`.
Just that. And **Typer** does the rest. If **Typer** detects `click-completion` installed, it will automatically create a command to install completion for the user's shell. If **Typer** detects `click-completion` installed, it will automatically create 2 *CLI options*:
* `--install-completion`: Install completion for the current shell. * `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
Then you can tell the user to run that command and the rest will just work.
## The power of Click
15 unmodified linesmodified:docs/index.md+14 added-8 removed
32 unmodified lines33 * **Intuitive to write**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.34 * **Easy to use**: It's easy to use for the final users. Automatic help commands, and (optional) automatic completion for all shells.35 * **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.36 * **Start simple**: The simplest example adds only 2 lines of code to your app: **1 import, 1 function call**.37-* **Grow large**: Grow in complexity as much as you want, create arbitrarily complex trees of commands and groups sub-commands, with options and arguments.37+* **Grow large**: Grow in complexity as much as you want, create arbitrarily complex trees of commands and groups subcommands, with options and arguments.38 39 ## Requirements40 41 Python 3.6+51 unmodified lines93 94 Usage: main.py [OPTIONS] NAME95 96 Options:97+ --install-completion Install completion for the current shell.98+ --show-completion Show completion for the current shell, to copy it or customize the installation.97- --help Show this message and exit.99+ --help Show this message and exit.100 101+// You get a ✨ auto completion ✨ for free, installed with --install-completion102+103 // Now pass the NAME argument104 $ python main.py Camila105 106 Hello Camila8 unmodified lines115 This was the simplest example possible.116 117 Now let's see one a bit more complex.118 115-### An example with two sub-commands119+### An example with two subcommands120 121 Modify the file `main.py`.122 119-Create a `typer.Typer()` app, and create two sub-commands with their parameters.123+Create a `typer.Typer()` app, and create two subcommands with their parameters.124 125 ```Python hl_lines="3 6 11 20"126 import typer127 20 unmodified lines148 And that will:149 150 * Explicitly create a `typer.Typer` app.151 * The previous `typer.run` actually creates one implicitly for you.148-* Add two sub-commands with `@app.command()`.152+* Add two subcommands with `@app.command()`.153 * Execute the `app()` itself, as if it was a function (instead of `typer.run`).154 155 ### Run the upgraded example156 5 unmodified lines162 163 Usage: main.py [OPTIONS] COMMAND [ARGS]...164 165 Options:166+ --install-completion Install completion for the current shell.167+ --show-completion Show completion for the current shell, to copy it or customize the installation.162- --help Show this message and exit.168+ --help Show this message and exit.169 170 Commands:171 goodbye172 hello173 168-// You have 2 sub-commands (the 2 functions): goodbye and hello174+// You have 2 subcommands (the 2 functions): goodbye and hello175 176 // Now get the --help for hello177 178 $ python main.py hello --help57 unmodified lines236 ```Python237 force: bool238 ```239 234-And similarly for **files**, **paths**, **enums** (choices), etc. And there are tools to create **groups of sub-commands**, add metadata, extra **validation**, etc.240+And similarly for **files**, **paths**, **enums** (choices), etc. And there are tools to create **groups of subcommands**, add metadata, extra **validation**, etc.241 242 **You get**: great editor support, including **completion** and **type checks** everywhere.243 244 **Your users get**: automatic **`--help`**, (optional) **autocompletion** in their terminal (Bash, Zsh, Fish, PowerShell).30 unmodified linesmodified:README.md+14 added-8 removed
32 unmodified lines33 * **Intuitive to write**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.34 * **Easy to use**: It's easy to use for the final users. Automatic help commands, and (optional) automatic completion for all shells.35 * **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.36 * **Start simple**: The simplest example adds only 2 lines of code to your app: **1 import, 1 function call**.37-* **Grow large**: Grow in complexity as much as you want, create arbitrarily complex trees of commands and groups sub-commands, with options and arguments.37+* **Grow large**: Grow in complexity as much as you want, create arbitrarily complex trees of commands and groups subcommands, with options and arguments.38 39 ## Requirements40 41 Python 3.6+51 unmodified lines93 94 Usage: main.py [OPTIONS] NAME95 96 Options:97+ --install-completion Install completion for the current shell.98+ --show-completion Show completion for the current shell, to copy it or customize the installation.97- --help Show this message and exit.99+ --help Show this message and exit.100 101+// You get a ✨ auto completion ✨ for free, installed with --install-completion102+103 // Now pass the NAME argument104 $ python main.py Camila105 106 Hello Camila8 unmodified lines115 This was the simplest example possible.116 117 Now let's see one a bit more complex.118 115-### An example with two sub-commands119+### An example with two subcommands120 121 Modify the file `main.py`.122 119-Create a `typer.Typer()` app, and create two sub-commands with their parameters.123+Create a `typer.Typer()` app, and create two subcommands with their parameters.124 125 ```Python hl_lines="3 6 11 20"126 import typer127 20 unmodified lines148 And that will:149 150 * Explicitly create a `typer.Typer` app.151 * The previous `typer.run` actually creates one implicitly for you.148-* Add two sub-commands with `@app.command()`.152+* Add two subcommands with `@app.command()`.153 * Execute the `app()` itself, as if it was a function (instead of `typer.run`).154 155 ### Run the upgraded example156 5 unmodified lines162 163 Usage: main.py [OPTIONS] COMMAND [ARGS]...164 165 Options:166+ --install-completion Install completion for the current shell.167+ --show-completion Show completion for the current shell, to copy it or customize the installation.162- --help Show this message and exit.168+ --help Show this message and exit.169 170 Commands:171 goodbye172 hello173 168-// You have 2 sub-commands (the 2 functions): goodbye and hello174+// You have 2 subcommands (the 2 functions): goodbye and hello175 176 // Now get the --help for hello177 178 $ python main.py hello --help57 unmodified lines236 ```Python237 force: bool238 ```239 234-And similarly for **files**, **paths**, **enums** (choices), etc. And there are tools to create **groups of sub-commands**, add metadata, extra **validation**, etc.240+And similarly for **files**, **paths**, **enums** (choices), etc. And there are tools to create **groups of subcommands**, add metadata, extra **validation**, etc.241 242 **You get**: great editor support, including **completion** and **type checks** everywhere.243 244 **Your users get**: automatic **`--help`**, (optional) **autocompletion** in their terminal (Bash, Zsh, Fish, PowerShell).30 unmodified lines