:pencil: Rewording in docs and fix typos
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by GitHub · parents bfcc190, d985d5b · Browse files · 4 files·+34 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+34 added−23 removed
- other:+34 added−23 removed
Provenance
- Commit
7b115c3- Tree
f58d3c8- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
bfcc190- Parent 2
d985d5b
4 files changed+34 added−23 removed
modified:docs/tutorial/first-steps.md+20 added-9 removed
156 unmodified lines157 your app wouldn't have a way to know which is the `name` and which the `lastname`. It expects the first *CLI argument* to be the `name` and the second *CLI argument* to be the `lastname`.158 159 ## What is a **CLI option**160 161-Here we will use the word **CLI option** to refer to **CLI parameters** passed to the CLI application with a specific name. Because they have a name they don't depend on the order. By default they are *optional* (not *required*).161+Here we will use the word **CLI option** to refer to *CLI parameters* passed to the CLI application with a specific name. For example, if you go to your terminal and type:162 163-They are a bit different from **CLI arguments** that you already created.164-165-If you go to your terminal and type:166-163 ```bash164 ls ./myproject --size165 ```166 2 unmodified lines169 * `ls` is the *command* (or "program", "CLI app").170 * `./myproject` is a *CLI argument*.171 * `--size` is an optional *CLI option*.172 177-A *CLI option* like `--size` doesn't depend on the order like a *CLI argument*.178-173 The program knows it has to show the size because it sees `--size`, not because of the order.174 175+A *CLI option* like `--size` doesn't depend on the order like a *CLI argument*.176+177 So, if you put the `--size` *before* the *CLI argument*, it still works:178 179 ```bash180 ls --size ./myproject181 ```182 183+The main visual difference between a *CLI option* and and a *CLI argument* is that the *CLI option* has `--` prepended to the name, like in "`--size`".184+185+A *CLI option* doesn't depend on the order because it has a predefined name (here it's `--size`). This is because the CLI app is looking specifically for a literal `--size` parameter or "flag", with that specific "name" (here the specific name is "`--size`"). The CLI app will check if you typed it or not, it will be actively looking for `--size` even if you didn't type it (to check if it's there or not).186+187+In contrast, the CLI app is not actively looking for the *CLI argument* with a text "`./myproject`", it has no way to know if you would type `./myproject` or `./mysuperawesomeproject` or anything else. It's just waiting to get whatever you give it. The only way to know that you refer to a specific *CLI argument* is because of the order. The same way that it knows that the first *CLI argument* was the `name` and the second was the `lastname`, but if you mixed the order, it wouldn't be able to handle it.188+189+Instead, with a *CLI option*, the order doesn't matter.190+191+Also, by default, a *CLI option* is *optional* (not *required*).192+193 !!! tip194 In this example above the *CLI option* `--size` is just a "flag", it's a boolean value, `True` or `False`.195 196 This one doesn't receive any values. But *CLI options* can also receive values like *CLI arguments*. You'll see how later.68 unmodified lines265 ```266 Good day Ms. Camila Gutiérrez.267 ```268 263-## A **CLI option* with a value269+## A *CLI option* with a value270 265-Let's convert the `lastname` from a *CLI argument* to a *CLI option*:271+To convert the `lastname` from a *CLI argument* to a *CLI option*, give it a default value of `""`:272 273 ```Python hl_lines="4"274 {!./src/first_steps/tutorial005.py!}275 ```19 unmodified lines295 296 !!! tip297 Notice the `--lastname`, and notice that it takes a textual value.298 299+ A *CLI option* with a value like `--lastname` (contrary to a *CLI option* without a value, a `bool` flag, like `--formal` or `--size`) takes as its value whatever is at the *right side* of the *CLI option*.300+301 If you call it without a `--lastname`:302 303 ```bash304 python main.py Camila16 unmodified lines321 ```322 Hello Camila Gutiérrez323 ```324 325+!!! tip326+ Notice that "`Gutiérrez`" is at the right side of `--lastname`. A *CLI option* with a value takes as its value whatever is at the *right side*.327+328 And as `--lastname` is now a *CLI option* that doesn't depend on the order, you can pass it before the name:329 330 ```bash331 python main.py --lastname Gutiérrez Camila77 unmodified linesmodified:docs/tutorial/intro.md+2 added-2 removed
15 unmodified lines161718192020212223247 unmodified lines3233343536363738394020 unmodified lines15 unmodified lines* `name` is of type `str` and is a required parameter.* `formal` is a `bool` and is by default `False`.* `intro` is a `str`, and by default is `None`, so it's optional.
These type hints are what gives you autocomplete in your editor and several other features.These type hints are what give you autocomplete in your editor and several other features.
Typer is based on these type hints.
## Intro7 unmodified linesSo you can come back and see exactly what you need.
## Run the code
All the code blocks can be copied and used directly (they are actually tested Python files).All 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:
```bash20 unmodified linesmodified:docs/features.md+2 added-2 removed
1233456737 unmodified lines4546474849495051525321 unmodified lines## Design based on **FastAPI**
**Typer** is the little sibling of <a href="https://fastapi.tiangolo.com" target="_blank">FastAPI</a>.**Typer** is <a href="https://fastapi.tiangolo.com" target="_blank">FastAPI</a>'s little sibling.
It follows the same design and ideas. If you know FastAPI, you already know **Typer**... more or less.
## Just Modern Python37 unmodified lines* 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. *
!!! note * Autocompletion!!! 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. 21 unmodified linesmodified:docs/index.md+10 added-10 removed
22 unmodified lines23 **Source Code**: <a href="https://github.com/tiangolo/typer" target="_blank">https://github.com/tiangolo/typer</a>24 25 ---26 27-Typer is library to build <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users love using and developers love creating. Based on Python 3.6+ type hints.27+Typer is library to build <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will love using and developers will love creating. Based on Python 3.6+ type hints.28 29-**Typer** is the little sibling of <a href="https://fastapi.tiangolo.com" target="_blank">FastAPI</a>. And it's intended to be the FastAPI of CLIs.29+**Typer** is <a href="https://fastapi.tiangolo.com" target="_blank">FastAPI</a>'s little sibling. And it's intended to be the FastAPI of CLIs.30 31 The key features are:32 33 * **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 sub-commands, with options and arguments.38 39 ## Requirements40 41 Python 3.6+42 43-Typer stands on the shoulders of a giant. Internally it uses <a href="https://click.palletsprojects.com/" target="_blank">Click</a>, that's the only dependency.43+Typer stands on the shoulders of a giant. Its only internal dependency is <a href="https://click.palletsprojects.com/" target="_blank">Click</a>.44 45 ## Installation46 47 ```bash63 unmodified lines111 ```112 113 ## Example upgrade114 115-The previous example was the extreme in terms of simplicity.115+This was the simplest example possible.116 117 Now let's see one a bit more complex.118 119 ### An example with two sub-commands159 unmodified lines279 ## Optional Dependencies280 281 Typer uses <a href="https://click.palletsprojects.com/" target="_blank">Click</a> internally. That's the only dependency.282 283-But you can install extras:283+But you can also install extras:284 285-* <a href="https://pypi.org/project/colorama/" target="_blank"><code>colorama</code></a>: and Click will automatically use it to make sure colors always work correctly, even in Windows.286- * Then you can use any tool you want to output colors in all the systems, including the integrated `typer.style()` and `typer.secho()` (provided by Click).285+* <a href="https://pypi.org/project/colorama/" target="_blank"><code>colorama</code></a>: and Click will automatically use it to make sure your terminal's colors always work correctly, even in Windows.286+ * Then you can use any tool you want to output your terminal's colors in all the systems, including the integrated `typer.style()` and `typer.secho()` (provided by Click).287 * Or any other tool, e.g. <a href="https://pypi.org/project/wasabi/" target="_blank"><code>wasabi</code></a>, <a href="https://github.com/erikrose/blessings" target="_blank"><code>blessings</code></a>.288 * <a href="https://github.com/click-contrib/click-completion" target="_blank"><code>click-completion</code></a>: and Typer will automatically configure it to provide completion for all the shells, including installation commands.289 290-You can install `typer` with `colorama` and `click-completion` with `pip3 install typer[all]`.290+You can install `typer` with `colorama` and `click-completion` with `pip install typer[all]`.291 292 ## Other tools and plug-ins293 294 Click has many plug-ins available that you can use. And there are many tools that help with command line applications that you can use as well, even if they are not related to Typer or Click.295 296 For example:297 298 * <a href="https://github.com/click-contrib/click-spinner" target="_blank"><code>click-spinner</code></a>: to show the user that you are loading data. A Click plug-in.299- * * There are several other Click plug-ins at <a href="https://github.com/click-contrib" target="_blank">click-contrib</a> that you can explore.299+ * There are several other Click plug-ins at <a href="https://github.com/click-contrib" target="_blank">click-contrib</a> that you can explore.300 * <a href="https://pypi.org/project/tabulate/" target="_blank"><code>tabulate</code></a>: to automatically display tabular data nicely. Independent of Click or typer.301 * etc... you can re-use many of the great available tools for building CLIs.302 303 ## License2 unmodified lines