Skip to content
Myr

full doc review and fixing typos

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Maria Camila Gutierrez · committed by Maria Camila Gutierrez · parent 071740f · Browse files · 4 files+25 added−14 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+25 added−14 removed

  • other:+25 added−14 removed

4 files+25 added−14 removed

modified:docs/tutorial/first-steps.md+20 added-9 removed
156 unmodified lines
157 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`.158159## What is a **CLI option**160161Here 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*).161Here 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:162163They are a bit different from **CLI arguments** that you already created.164165If you go to your terminal and type:166163```bash164ls ./myproject --size165```166
2 unmodified lines
169* `ls` is the *command* (or "program", "CLI app").170* `./myproject` is a *CLI argument*.171* `--size` is an optional *CLI option*.172177A *CLI option* like `--size` doesn't depend on the order like a *CLI argument*.178173The program knows it has to show the size because it sees `--size`, not because of the order.174175A *CLI option* like `--size` doesn't depend on the order like a *CLI argument*.176177So, if you put the `--size` *before* the *CLI argument*, it still works:178179```bash180ls --size ./myproject181```182183The 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`".184185A *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).186187In 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.188189Instead, with a *CLI option*, the order doesn't matter.190191Also, by default, a *CLI option* is *optional* (not *required*).192193!!! tip194 In this example above the *CLI option* `--size` is just a "flag", it's a boolean value, `True` or `False`.195196 This one doesn't receive any values. But *CLI options* can also receive values like *CLI arguments*. You'll see how later.
68 unmodified lines
265```266Good day Ms. Camila Gutiérrez.267```268263## A **CLI option* with a value269## A *CLI option* with a value270265Let's convert the `lastname` from a *CLI argument* to a *CLI option*:271To convert the `lastname` from a *CLI argument* to a *CLI option*, give it a default value of `""`:272273```Python hl_lines="4"274{!./src/first_steps/tutorial005.py!}275```
19 unmodified lines
295296!!! tip297 Notice the `--lastname`, and notice that it takes a textual value.298299 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*.300301If you call it without a `--lastname`:302303```bash304python main.py Camila
16 unmodified lines
321```322Hello Camila Gutiérrez323```324325!!! 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*.327328And as `--lastname` is now a *CLI option* that doesn't depend on the order, you can pass it before the name:329330```bash331python main.py --lastname Gutiérrez Camila
77 unmodified lines
modified:docs/tutorial/intro.md+2 added-2 removed
modified:docs/features.md+2 added-2 removed
modified:docs/index.md+1 added-1 removed
285 unmodified lines
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.289290You can install `typer` with `colorama` and `click-completion` with `pip3 install typer[all]`.290You can install `typer` with `colorama` and `click-completion` with `pip install typer[all]`.291292## Other tools and plug-ins293294Click 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.
11 unmodified lines