Skip to content
Myr

:memo: Fix typos, update docs and descriptions

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 Sebastián Ramírez · parent 5aa9bdd · Browse files · 4 files+24 added−12 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+24 added−12 removed

  • other:+24 added−12 removed

4 files+24 added−12 removed

modified:docs/tutorial/first-steps.md+21 added-9 removed
20 unmodified lines
2122// Now check the --help23$ python main.py --help2425Usage: tryit.py [OPTIONS]25Usage: main.py [OPTIONS]2627Options:28 --install-completion Install completion for the current shell.29 --show-completion Show completion for the current shell, to copy it or customize the installation.
143 unmodified lines
173</div>174175The 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`".176177A *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).177A *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 (also known as "flag" or "switch"), 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).178179In 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.179In 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 `./my-super-awesome-project` 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.180181Instead, with a *CLI option*, the order doesn't matter.182183Also, by default, a *CLI option* is *optional* (not *required*).184185So, by default:186187* A *CLI argument* is **required**188* A *CLI option* is **optional**189190But the *required* and *optional* defaults can be changed.191192So, the main and **most important** difference is that:193194* *CLI options* **start with `--`** and don't depend on the order195* *CLI arguments* depend on the **sequence order**196197!!! tip186 In this example above the *CLI option* `--size` is just a "flag", it's a boolean value, `True` or `False`.198 In this example above the *CLI option* `--size` is just a "flag" or "switch" that will contain a boolean value, `True` or `False`, depending on if it was added to the command or not.199200 This one doesn't receive any values. But *CLI options* can also receive values like *CLI arguments*. You'll see how later.201202## Add one *CLI option*
127 unmodified lines
330331```console332$ python main.py --help333322Usage: tutorial006.py [OPTIONS] NAME334Usage: main.py [OPTIONS] NAME335336 Say hi to NAME, optionally with a --lastname.337338 If --formal is used, say hi very formally.
66 unmodified lines
405And a parameter like `name`, that doesn't have a default value, is considered *required*.406407### In CLIs408397When talking about command line interfaces/applications, the words "argument" and "parameter" are commonly used to refer to that data passed to a CLI app, those parameters.409When talking about command line interfaces/applications, the words **"argument"** and **"parameter"** are commonly used to refer to that data passed to a CLI app, those parameters.410399But those words don't imply anything about the data being required, needing to be passed in a certain order, nor having a flag like `--lastname`.411But those words **don't imply** anything about the data being required, needing to be passed in a certain order, nor having a flag like `--lastname`.412401The parameters that come with a flag like `--lastname` and a value (or when the flag itself is the value, like `--formal`) are commonly optional, not required. So, when talking about CLIs it's common to call them *optional arguments* or *optional parameters*.413The parameters that come with a name like `--lastname` (and optionally a value) are commonly optional, not required. So, when talking about CLIs it's common to call them **optional arguments** or **optional parameters**. Sometimes these *optional parameters* that start with `--` are also called a **flag** or a **switch**.414415In reality, the parameters that require an order can be made *optional* too. And the ones that come with a flag (like `--lastname`) can be *required* too.416417### In **Typer**
1 unmodified line
419To try and make it a bit easier, we'll normally use the words "parameter" or "argument" to refer to Python functions.420421We'll use ***CLI argument*** to refer to those *CLI parameters* that depend on an order. That are **required** by default.422411And we'll use ***CLI option*** to refer to those *CLI parameters* that depend on a flag (like `--lastname`). That are **optional** by default.423And we'll use ***CLI option*** to refer to those *CLI parameters* that depend on a name that starts with `--` (like `--lastname`). That are **optional** by default.424425We will use ***CLI parameter*** to refer to both, *CLI arguments* and *CLI options*.
modified:docs/index.md+1 added-1 removed
96 unmodified lines
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.99 --help Show this message and exit.100101// You get a ✨ auto completion ✨ for free, installed with --install-completion101// You get ✨ auto completion ✨ for free, installed with --install-completion102103// Now pass the NAME argument104$ python main.py Camila105
169 unmodified lines
modified:docs/release-notes.md+1 added-1 removed
modified:README.md+1 added-1 removed
96 unmodified lines
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.99 --help Show this message and exit.100101// You get a ✨ auto completion ✨ for free, installed with --install-completion101// You get ✨ auto completion ✨ for free, installed with --install-completion102103// Now pass the NAME argument104$ python main.py Camila105
169 unmodified lines