🎨 Tweak external links' format #36
This commit is contained in:
commit
38c19f059f
22 changed files with 67 additions and 63 deletions
16
README.md
16
README.md
|
@ -40,7 +40,7 @@ The key features are:
|
|||
|
||||
Python 3.6+
|
||||
|
||||
Typer stands on the shoulders of a giant. Its only internal dependency is <a href="https://click.palletsprojects.com/" target="_blank">Click</a>.
|
||||
Typer stands on the shoulders of a giant. Its only internal dependency is <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a>.
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -247,14 +247,14 @@ For a more complete example including more features, see the <a href="https://ty
|
|||
|
||||
## Optional Dependencies
|
||||
|
||||
Typer uses <a href="https://click.palletsprojects.com/" target="_blank">Click</a> internally. That's the only dependency.
|
||||
Typer uses <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a> internally. That's the only dependency.
|
||||
|
||||
But you can also install extras:
|
||||
|
||||
* <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.
|
||||
* <a href="https://pypi.org/project/colorama/" class="external-link" 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.
|
||||
* 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).
|
||||
* 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>.
|
||||
* <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.
|
||||
* Or any other tool, e.g. <a href="https://pypi.org/project/wasabi/" class="external-link" target="_blank"><code>wasabi</code></a>, <a href="https://github.com/erikrose/blessings" class="external-link" target="_blank"><code>blessings</code></a>.
|
||||
* <a href="https://github.com/click-contrib/click-completion" class="external-link" target="_blank"><code>click-completion</code></a>: and Typer will automatically configure it to provide completion for all the shells, including installation commands.
|
||||
|
||||
You can install `typer` with `colorama` and `click-completion` with `pip install typer[all]`.
|
||||
|
||||
|
@ -264,9 +264,9 @@ Click has many plug-ins available that you can use. And there are many tools tha
|
|||
|
||||
For example:
|
||||
|
||||
* <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.
|
||||
* There are several other Click plug-ins at <a href="https://github.com/click-contrib" target="_blank">click-contrib</a> that you can explore.
|
||||
* <a href="https://pypi.org/project/tabulate/" target="_blank"><code>tabulate</code></a>: to automatically display tabular data nicely. Independent of Click or typer.
|
||||
* <a href="https://github.com/click-contrib/click-spinner" class="external-link" target="_blank"><code>click-spinner</code></a>: to show the user that you are loading data. A Click plug-in.
|
||||
* There are several other Click plug-ins at <a href="https://github.com/click-contrib" class="external-link" target="_blank">click-contrib</a> that you can explore.
|
||||
* <a href="https://pypi.org/project/tabulate/" class="external-link" target="_blank"><code>tabulate</code></a>: to automatically display tabular data nicely. Independent of Click or typer.
|
||||
* etc... you can re-use many of the great available tools for building CLIs.
|
||||
|
||||
## License
|
||||
|
|
|
@ -7,3 +7,7 @@
|
|||
.termy [data-termynal] {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
a.external-link::after {
|
||||
content: " [↪]";
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ You will rarely need to come back to the docs.
|
|||
|
||||
Here's how your editor might help you:
|
||||
|
||||
* in <a href="https://code.visualstudio.com/" target="_blank">Visual Studio Code</a>:
|
||||
* in <a href="https://code.visualstudio.com/" class="external-link" target="_blank">Visual Studio Code</a>:
|
||||
|
||||
![editor support](img/vscode-completion.png)
|
||||
|
||||
* in <a href="https://www.jetbrains.com/pycharm/" target="_blank">PyCharm</a>:
|
||||
* in <a href="https://www.jetbrains.com/pycharm/" class="external-link" target="_blank">PyCharm</a>:
|
||||
|
||||
![editor support](img/pycharm-completion.png)
|
||||
|
||||
|
@ -60,7 +60,7 @@ The resulting CLI apps created with **Typer** have the nice features of many "pr
|
|||
|
||||
## The power of Click
|
||||
|
||||
<a href="https://click.palletsprojects.com" target="_blank">Click</a> is one of the most popular tools for building CLIs in Python.
|
||||
<a href="https://click.palletsprojects.com" class="external-link" target="_blank">Click</a> is one of the most popular tools for building CLIs in Python.
|
||||
|
||||
**Typer** is based on it, so you get all its benefits, plug-ins, robustness, etc.
|
||||
|
||||
|
|
|
@ -10,13 +10,13 @@ And there are several ways to get help too.
|
|||
|
||||
## Star **Typer** in GitHub
|
||||
|
||||
You can "star" Typer in GitHub (clicking the star button at the top right): <a href="https://github.com/tiangolo/typer" target="_blank">https://github.com/tiangolo/typer</a>.
|
||||
You can "star" Typer in GitHub (clicking the star button at the top right): <a href="https://github.com/tiangolo/typer" class="external-link" target="_blank">https://github.com/tiangolo/typer</a>.
|
||||
|
||||
By adding a star, other users will be able to find it more easily and see that it has been already useful for others.
|
||||
|
||||
## Watch the GitHub repository for releases
|
||||
|
||||
You can "watch" Typer in GitHub (clicking the "watch" button at the top right): <a href="https://github.com/tiangolo/typer" target="_blank">https://github.com/tiangolo/typer</a>.
|
||||
You can "watch" Typer in GitHub (clicking the "watch" button at the top right): <a href="https://github.com/tiangolo/typer" class="external-link" target="_blank">https://github.com/tiangolo/typer</a>.
|
||||
|
||||
There you can select "Releases only".
|
||||
|
||||
|
@ -24,28 +24,28 @@ Doing it, you will receive notifications (in your email) whenever there's a new
|
|||
|
||||
## Connect with the author
|
||||
|
||||
You can connect with <a href="https://tiangolo.com" target="_blank">me (Sebastián Ramírez / `tiangolo`)</a>, the author.
|
||||
You can connect with <a href="https://tiangolo.com" class="external-link" target="_blank">me (Sebastián Ramírez / `tiangolo`)</a>, the author.
|
||||
|
||||
You can:
|
||||
|
||||
* <a href="https://github.com/tiangolo" target="_blank">Follow me on **GitHub**</a>.
|
||||
* <a href="https://github.com/tiangolo" class="external-link" target="_blank">Follow me on **GitHub**</a>.
|
||||
* See other Open Source projects I have created that could help you.
|
||||
* Follow me to see when I create a new Open Source project.
|
||||
* <a href="https://twitter.com/tiangolo" target="_blank">Follow me on **Twitter**</a>.
|
||||
* <a href="https://twitter.com/tiangolo" class="external-link" target="_blank">Follow me on **Twitter**</a>.
|
||||
* Tell me how you use Typer (I love to hear that).
|
||||
* Ask questions.
|
||||
* <a href="https://www.linkedin.com/in/tiangolo/" target="_blank">Connect with me on **Linkedin**</a>.
|
||||
* <a href="https://www.linkedin.com/in/tiangolo/" class="external-link" target="_blank">Connect with me on **Linkedin**</a>.
|
||||
* Talk to me.
|
||||
* Endorse me or recommend me :)
|
||||
* Read what I write (or follow me):
|
||||
* Read other ideas, articles and tools I have created.
|
||||
* Follow me to see when I publish something new.
|
||||
* On <a href="https://dev.to/tiangolo" target="_blank">**Dev.to**</a>.
|
||||
* On <a href="https://medium.com/@tiangolo" target="_blank">**Medium**</a>.
|
||||
* On <a href="https://dev.to/tiangolo" class="external-link" target="_blank">**Dev.to**</a>.
|
||||
* On <a href="https://medium.com/@tiangolo" class="external-link" target="_blank">**Medium**</a>.
|
||||
|
||||
## Tweet about **Typer**
|
||||
|
||||
<a href="https://twitter.com/compose/tweet?text=I'm loving Typer because... https://github.com/tiangolo/typer cc @tiangolo" target="_blank">Tweet about **Typer**</a> and let me and others know why you like it.
|
||||
<a href="https://twitter.com/compose/tweet?text=I'm loving Typer because... https://github.com/tiangolo/typer cc @tiangolo" class="external-link" target="_blank">Tweet about **Typer**</a> and let me and others know why you like it.
|
||||
|
||||
## Let me know how are you using **Typer**
|
||||
|
||||
|
@ -53,18 +53,18 @@ I love to hear about how **Typer** is being used, what have you liked in it, in
|
|||
|
||||
You can let me know:
|
||||
|
||||
* <a href="https://twitter.com/compose/tweet?text=Hey @tiangolo, I'm using Typer at..." target="_blank">On **Twitter**</a>.
|
||||
* <a href="https://www.linkedin.com/in/tiangolo/" target="_blank">On **Linkedin**</a>.
|
||||
* <a href="https://dev.to/tiangolo" target="_blank">On **Dev.to**</a>.
|
||||
* <a href="https://medium.com/@tiangolo" target="_blank">On **Medium**</a>.
|
||||
* <a href="https://twitter.com/compose/tweet?text=Hey @tiangolo, I'm using Typer at..." class="external-link" target="_blank">On **Twitter**</a>.
|
||||
* <a href="https://www.linkedin.com/in/tiangolo/" class="external-link" target="_blank">On **Linkedin**</a>.
|
||||
* <a href="https://dev.to/tiangolo" class="external-link" target="_blank">On **Dev.to**</a>.
|
||||
* <a href="https://medium.com/@tiangolo" class="external-link" target="_blank">On **Medium**</a>.
|
||||
|
||||
## Help others with issues in GitHub
|
||||
|
||||
You can see <a href="https://github.com/tiangolo/typer/issues" target="_blank">existing issues</a> and try and help others.
|
||||
You can see <a href="https://github.com/tiangolo/typer/issues" class="external-link" target="_blank">existing issues</a> and try and help others.
|
||||
|
||||
## Watch the GitHub repository
|
||||
|
||||
You can "watch" Typer in GitHub (clicking the "watch" button at the top right): <a href="https://github.com/tiangolo/typer" target="_blank">https://github.com/tiangolo/typer</a>.
|
||||
You can "watch" Typer in GitHub (clicking the "watch" button at the top right): <a href="https://github.com/tiangolo/typer" class="external-link" target="_blank">https://github.com/tiangolo/typer</a>.
|
||||
|
||||
If you select "Watching" instead of "Releases only", you will receive notifications when someone creates a new issue.
|
||||
|
||||
|
@ -72,7 +72,7 @@ Then you can try and help them solving those issues.
|
|||
|
||||
## Create issues
|
||||
|
||||
You can <a href="https://github.com/tiangolo/typer/issues/new/choose" target="_blank">create a new issue</a> in the GitHub repository, for example to:
|
||||
You can <a href="https://github.com/tiangolo/typer/issues/new/choose" class="external-link" target="_blank">create a new issue</a> in the GitHub repository, for example to:
|
||||
|
||||
* Report a bug/issue.
|
||||
* Suggest a new feature.
|
||||
|
@ -80,7 +80,7 @@ You can <a href="https://github.com/tiangolo/typer/issues/new/choose" target="_b
|
|||
|
||||
## Create a Pull Request
|
||||
|
||||
You can <a href="https://github.com/tiangolo/typer" target="_blank">create a Pull Request</a>, for example:
|
||||
You can <a href="https://github.com/tiangolo/typer" class="external-link" target="_blank">create a Pull Request</a>, for example:
|
||||
|
||||
* To fix a typo you found on the documentation.
|
||||
* To propose new documentation sections.
|
||||
|
|
|
@ -40,7 +40,7 @@ The key features are:
|
|||
|
||||
Python 3.6+
|
||||
|
||||
Typer stands on the shoulders of a giant. Its only internal dependency is <a href="https://click.palletsprojects.com/" target="_blank">Click</a>.
|
||||
Typer stands on the shoulders of a giant. Its only internal dependency is <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a>.
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -247,14 +247,14 @@ For a more complete example including more features, see the <a href="https://ty
|
|||
|
||||
## Optional Dependencies
|
||||
|
||||
Typer uses <a href="https://click.palletsprojects.com/" target="_blank">Click</a> internally. That's the only dependency.
|
||||
Typer uses <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a> internally. That's the only dependency.
|
||||
|
||||
But you can also install extras:
|
||||
|
||||
* <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.
|
||||
* <a href="https://pypi.org/project/colorama/" class="external-link" 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.
|
||||
* 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).
|
||||
* 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>.
|
||||
* <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.
|
||||
* Or any other tool, e.g. <a href="https://pypi.org/project/wasabi/" class="external-link" target="_blank"><code>wasabi</code></a>, <a href="https://github.com/erikrose/blessings" class="external-link" target="_blank"><code>blessings</code></a>.
|
||||
* <a href="https://github.com/click-contrib/click-completion" class="external-link" target="_blank"><code>click-completion</code></a>: and Typer will automatically configure it to provide completion for all the shells, including installation commands.
|
||||
|
||||
You can install `typer` with `colorama` and `click-completion` with `pip install typer[all]`.
|
||||
|
||||
|
@ -264,9 +264,9 @@ Click has many plug-ins available that you can use. And there are many tools tha
|
|||
|
||||
For example:
|
||||
|
||||
* <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.
|
||||
* There are several other Click plug-ins at <a href="https://github.com/click-contrib" target="_blank">click-contrib</a> that you can explore.
|
||||
* <a href="https://pypi.org/project/tabulate/" target="_blank"><code>tabulate</code></a>: to automatically display tabular data nicely. Independent of Click or typer.
|
||||
* <a href="https://github.com/click-contrib/click-spinner" class="external-link" target="_blank"><code>click-spinner</code></a>: to show the user that you are loading data. A Click plug-in.
|
||||
* There are several other Click plug-ins at <a href="https://github.com/click-contrib" class="external-link" target="_blank">click-contrib</a> that you can explore.
|
||||
* <a href="https://pypi.org/project/tabulate/" class="external-link" target="_blank"><code>tabulate</code></a>: to automatically display tabular data nicely. Independent of Click or typer.
|
||||
* etc... you can re-use many of the great available tools for building CLIs.
|
||||
|
||||
## License
|
||||
|
|
|
@ -32,7 +32,7 @@ If the first element is a `Path` object the next ones (after the `/`) can be `st
|
|||
|
||||
And it will create a new `Path` object from that.
|
||||
|
||||
If you want a quick guide on using `Path()` you can check <a href="https://realpython.com/python-pathlib/" target="_blank">this post on Real Python</a> or <a href="https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/" target="_blank">this post by Trey Hunner</a>.
|
||||
If you want a quick guide on using `Path()` you can check <a href="https://realpython.com/python-pathlib/" class="external-link" target="_blank">this post on Real Python</a> or <a href="https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/" class="external-link" target="_blank">this post by Trey Hunner</a>.
|
||||
|
||||
In the code above, we are also explicitly declaring `config_path` as having type `Path` to help the editor provide completion and type checks:
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ __init__.py test_tutorial
|
|||
|
||||
### An alternative *CLI argument* declaration
|
||||
|
||||
In the <a href="https://typer.tiangolo.com/tutorial/first-steps/#add-a-cli-argument" target="_blank">First Steps</a> you saw how to add a *CLI argument*:
|
||||
In the <a href="https://typer.tiangolo.com/tutorial/first-steps/#add-a-cli-argument" class="external-link" target="_blank">First Steps</a> you saw how to add a *CLI argument*:
|
||||
|
||||
```Python hl_lines="4"
|
||||
{!./src/first_steps/tutorial002.py!}
|
||||
|
@ -70,7 +70,7 @@ As we no longer have the Python function default value (or its absence) to tell
|
|||
To make it *required*, we pass `...` as the first function argument passed to `typer.Argument(...)`.
|
||||
|
||||
!!! info
|
||||
If you hadn't seen that `...` before: it is a a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" target="_blank">part of Python and is called "Ellipsis"</a>.
|
||||
If you hadn't seen that `...` before: it is a a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" class="external-link" target="_blank">part of Python and is called "Ellipsis"</a>.
|
||||
|
||||
All we did there achieves the same thing as before, a **required** *CLI argument*:
|
||||
|
||||
|
@ -191,7 +191,7 @@ For that reason, Typer (actually Click underneath) doesn't attempt to automatica
|
|||
|
||||
And you should document them as part of the CLI app documentation, normally in a <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>.
|
||||
|
||||
Check the last example from the <a href="https://typer.tiangolo.com/tutorial/first-steps/#document-your-cli-app" target="_blank">First Steps</a>:
|
||||
Check the last example from the <a href="https://typer.tiangolo.com/tutorial/first-steps/#document-your-cli-app" class="external-link" target="_blank">First Steps</a>:
|
||||
|
||||
```Python hl_lines="5 6 7 8 9"
|
||||
{!./src/first_steps/tutorial006.py!}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
If you need a refreshed about how to use Python type hints, check the first part of <a href="https://fastapi.tiangolo.com/python-types/" target="_blank">FastAPI's Python types intro</a>.
|
||||
|
||||
You can also check the <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" target="_blank">mypy cheat sheet</a>.
|
||||
You can also check the <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" class="external-link" target="_blank">mypy cheat sheet</a>.
|
||||
|
||||
In short (very short), you can declare a function with parameters like:
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ is_wizard = user[2]
|
|||
!!! tip
|
||||
Notice that the default is a tuple with `(None, None, None)`.
|
||||
|
||||
You cannot simply use `None` here as the default because <a href="https://github.com/pallets/click/issues/472" target="_blank">Click doesn't support it</a>.
|
||||
You cannot simply use `None` here as the default because <a href="https://github.com/pallets/click/issues/472" class="external-link" target="_blank">Click doesn't support it</a>.
|
||||
|
||||
## Check it
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ You can pass the *CLI option* name that you want to have in the next positional
|
|||
Here you are passing the string `"--name"` as the second positional argument to `typer.Option()`.
|
||||
|
||||
!!! info
|
||||
"<a href="https://docs.python.org/3.8/glossary.html#term-argument" target="_blank">Positional</a>" means that it's not a function argument with a keyword name.
|
||||
"<a href="https://docs.python.org/3.8/glossary.html#term-argument" class="external-link" target="_blank">Positional</a>" means that it's not a function argument with a keyword name.
|
||||
|
||||
For example `show_default=True` is a keyword argument. "`show_default`" is the keyword.
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ But if you really want, you can change that.
|
|||
To make a *CLI option* required, pass `...` to `typer.Option()`.
|
||||
|
||||
!!! info
|
||||
If you hadn't seen that `...` before: it is a a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" target="_blank">part of Python and is called "Ellipsis"</a>.
|
||||
If you hadn't seen that `...` before: it is a a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" class="external-link" target="_blank">part of Python and is called "Ellipsis"</a>.
|
||||
|
||||
That will tell **Typer** that it's still a *CLI option*, but it doesn't have a default value, and it's required.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
You can specify a *CLI parameter* as a Python <a href="https://docs.python.org/3/library/datetime.html" target="_blank">`datetime`</a>.
|
||||
You can specify a *CLI parameter* as a Python <a href="https://docs.python.org/3/library/datetime.html" class="external-link" target="_blank">`datetime`</a>.
|
||||
|
||||
Your function will receive a standard Python `datetime` object, and again, your editor will give you completion, etc.
|
||||
|
||||
|
@ -42,7 +42,7 @@ Error: Invalid value for "[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]": inval
|
|||
|
||||
You can also customize the formats received for the `datetime` with the `formats` parameter.
|
||||
|
||||
`formats` receives a list of strings with the date formats that would be passed to <a href="https://docs.python.org/3/library/datetime.html#datetime.date.strftime" target="_blank">datetime.strptime()</a>.
|
||||
`formats` receives a list of strings with the date formats that would be passed to <a href="https://docs.python.org/3/library/datetime.html#datetime.date.strftime" class="external-link" target="_blank">datetime.strptime()</a>.
|
||||
|
||||
For example, let's imagine that you want to accept an ISO formatted datetime, but for some strange reason, you also want to accept a format with:
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
To define a *CLI parameter* that can take a value from a predefined set of values you can use a standard Python <a href="https://docs.python.org/3/library/enum.html" target="_blank">`enum.Enum`</a>:
|
||||
To define a *CLI parameter* that can take a value from a predefined set of values you can use a standard Python <a href="https://docs.python.org/3/library/enum.html" class="external-link" target="_blank">`enum.Enum`</a>:
|
||||
|
||||
```Python hl_lines="1 6 7 8 9 12 13"
|
||||
{!./src/parameter_types/enum/tutorial001.py!}
|
||||
|
|
|
@ -5,7 +5,7 @@ Apart from `Path` *CLI parameters* you can also declare some types of "files".
|
|||
|
||||
You can read and write data with `Path` the same way.
|
||||
|
||||
The difference is that these types will give you a Python <a href="https://docs.python.org/3/glossary.html#term-file-object" target="_blank">file-like object</a> instead of a Python <a href="https://docs.python.org/3/library/pathlib.html#basic-use" target="_blank">Path</a>.
|
||||
The difference is that these types will give you a Python <a href="https://docs.python.org/3/glossary.html#term-file-object" class="external-link" target="_blank">file-like object</a> instead of a Python <a href="https://docs.python.org/3/library/pathlib.html#basic-use" class="external-link" target="_blank">Path</a>.
|
||||
|
||||
A "file-like object" is the same type of object returned by `open()` as in:
|
||||
|
||||
|
@ -168,7 +168,7 @@ $ ls ./binary.dat
|
|||
|
||||
You can use several configuration parameters for these types (classes) in `typer.Option()` and `typer.Argument()`:
|
||||
|
||||
* `mode`: controls the "<a href="https://docs.python.org/3/library/functions.html#open" target="_blank">mode</a>" to open the file with.
|
||||
* `mode`: controls the "<a href="https://docs.python.org/3/library/functions.html#open" class="external-link" target="_blank">mode</a>" to open the file with.
|
||||
* It's automatically set for you by using the classes above.
|
||||
* Read more about it below.
|
||||
* `encoding`: to force a specific encoding, e.g. `"utf-8"`.
|
||||
|
@ -178,7 +178,7 @@ You can use several configuration parameters for these types (classes) in `typer
|
|||
|
||||
## Advanced `mode`
|
||||
|
||||
By default, **Typer** will configure the <a href="https://docs.python.org/3/library/functions.html#open" target="_blank">`mode`</a> for you:
|
||||
By default, **Typer** will configure the <a href="https://docs.python.org/3/library/functions.html#open" class="external-link" target="_blank">`mode`</a> for you:
|
||||
|
||||
* `typer.FileText`: `mode="r"`, to read text.
|
||||
* `typer.FileTextWrite`: `mode="w"`, to write text.
|
||||
|
|
|
@ -62,4 +62,4 @@ See more about specific types and validations in the next sections...
|
|||
|
||||
|
||||
!!! info "Technical Details"
|
||||
All the types you will see in the next sections are handled underneath by <a href="https://click.palletsprojects.com/en/7.x/parameters/#parameter-types" target="_blank">Click's Parameter Types</a>.
|
||||
All the types you will see in the next sections are handled underneath by <a href="https://click.palletsprojects.com/en/7.x/parameters/#parameter-types" class="external-link" target="_blank">Click's Parameter Types</a>.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
You can declare a *CLI parameter* to be a standard Python <a href="https://docs.python.org/3/library/pathlib.html#basic-use" target="_blank">`pathlib.Path`</a>.
|
||||
You can declare a *CLI parameter* to be a standard Python <a href="https://docs.python.org/3/library/pathlib.html#basic-use" class="external-link" target="_blank">`pathlib.Path`</a>.
|
||||
|
||||
This is what you would do for directory paths, file paths, etc:
|
||||
|
||||
|
@ -55,7 +55,7 @@ You can perform several validations for `Path` *CLI parameters*:
|
|||
It will not expand a tilde-prefix (something with `~`, like `~/Documents/`), as this is supposed to be done by the shell only.
|
||||
|
||||
!!! tip
|
||||
All these parameters come directly from <a href="https://click.palletsprojects.com/en/7.x/parameters/#parameter-types" target="_blank">Click</a>.
|
||||
All these parameters come directly from <a href="https://click.palletsprojects.com/en/7.x/parameters/#parameter-types" class="external-link" target="_blank">Click</a>.
|
||||
|
||||
For example:
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
!!! info
|
||||
A UUID is a <a href="https://en.wikipedia.org/wiki/Universally_unique_identifier" target="_blank">"Universally Unique Identifier"</a>.
|
||||
A UUID is a <a href="https://en.wikipedia.org/wiki/Universally_unique_identifier" class="external-link" target="_blank">"Universally Unique Identifier"</a>.
|
||||
|
||||
It's a standard format for identifiers, like passport numbers, but for anything, not just people in countries.
|
||||
|
||||
|
@ -23,7 +23,7 @@ You can declare a *CLI parameter* as a UUID:
|
|||
{!./src/parameter_types/uuid/tutorial001.py!}
|
||||
```
|
||||
|
||||
Your Python code will receive a standard Python <a href="https://docs.python.org/3.8/library/uuid.html" target="_blank">`UUID`</a> object with all its attributes and methods, and as you are annotating your function parameter with that type, you will have type checks, autocompletion in your editor, etc.
|
||||
Your Python code will receive a standard Python <a href="https://docs.python.org/3.8/library/uuid.html" class="external-link" target="_blank">`UUID`</a> object with all its attributes and methods, and as you are annotating your function parameter with that type, you will have type checks, autocompletion in your editor, etc.
|
||||
|
||||
Check it:
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ You can use `typer.echo()` to print to the screen:
|
|||
The reason to use `typer.echo()` instead of just `print()` is that it applies some error corrections in case the terminal is misconfigured, and it will properly output color if it's supported.
|
||||
|
||||
!!! info
|
||||
`typer.echo()` comes directly from Click, you can read more about it in <a href="https://click.palletsprojects.com/en/7.x/quickstart/#echoing" target="_blank">Click's docs</a>.
|
||||
`typer.echo()` comes directly from Click, you can read more about it in <a href="https://click.palletsprojects.com/en/7.x/quickstart/#echoing" class="external-link" target="_blank">Click's docs</a>.
|
||||
|
||||
Check it:
|
||||
|
||||
|
@ -24,7 +24,7 @@ Hello World
|
|||
## Color
|
||||
|
||||
!!! info
|
||||
For colors to work correctly on Windows you need to also install <a href="https://pypi.org/project/colorama/" target="_blank">`colorama`</a>.
|
||||
For colors to work correctly on Windows you need to also install <a href="https://pypi.org/project/colorama/" class="external-link" target="_blank">`colorama`</a>.
|
||||
|
||||
You don't need to call `colorama.init()`. Typer (actually Click) will handle it underneath.
|
||||
|
||||
|
@ -65,7 +65,7 @@ You can pass these function arguments to `typer.style()`:
|
|||
* `reset`: by default a reset-all code is added at the end of the string which means that styles do not carry over. This can be disabled to compose styles.
|
||||
|
||||
!!! info
|
||||
You can read more about it in <a href="https://click.palletsprojects.com/en/7.x/api/#click.style" target="_blank">Click's docs about `style()`</a>
|
||||
You can read more about it in <a href="https://click.palletsprojects.com/en/7.x/api/#click.style" class="external-link" target="_blank">Click's docs about `style()`</a>
|
||||
|
||||
## `typer.secho()` - style and print
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ Processed 100 user IDs.
|
|||
|
||||
### About the function with `yield`
|
||||
|
||||
If you hadn't seen something like that `yield` above, that's a "<a href="https://docs.python.org/3/glossary.html#term-generator" target="_blank">generator</a>".
|
||||
If you hadn't seen something like that `yield` above, that's a "<a href="https://docs.python.org/3/glossary.html#term-generator" class="external-link" target="_blank">generator</a>".
|
||||
|
||||
You can iterate over that function with a `for` and at each iteration it will give you the value at `yield`.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
When you need to ask the user for info interactively you should normally use <a href="https://typer.tiangolo.com/tutorial/options/prompt/" target="_blank">*CLI Option*s with Prompt</a>, because they allow using the CLI program in a non-interactive way (for example, a Bash script could use it).
|
||||
When you need to ask the user for info interactively you should normally use <a href="https://typer.tiangolo.com/tutorial/options/prompt/" class="external-link" target="_blank">*CLI Option*s with Prompt</a>, because they allow using the CLI program in a non-interactive way (for example, a Bash script could use it).
|
||||
|
||||
But if you absolutely need to ask for interactive information without using a *CLI option*, you can use `typer.prompt()`:
|
||||
|
||||
|
@ -22,7 +22,7 @@ Hello Camila
|
|||
|
||||
## Confirm
|
||||
|
||||
There's also an alternative to ask for confirmation. Again, if possible, you should use a <a href="https://typer.tiangolo.com/tutorial/options/prompt/" target="_blank">*CLI Option* with a confirmation prompt</a>:
|
||||
There's also an alternative to ask for confirmation. Again, if possible, you should use a <a href="https://typer.tiangolo.com/tutorial/options/prompt/" class="external-link" target="_blank">*CLI Option* with a confirmation prompt</a>:
|
||||
|
||||
```Python hl_lines="5"
|
||||
{!./src/prompt/tutorial002.py!}
|
||||
|
|
|
@ -51,7 +51,7 @@ Creating user: Camila
|
|||
|
||||
If a callback was added when creating the `typer.Typer()` app, it's possible to override it with a new one using `@app.callback()`.
|
||||
|
||||
This is the same information you saw on the section about <a href="https://typer.tiangolo.com/tutorial/commands/callback/" target="_blank">Commands - Typer Callback</a>, and it applies the same for sub-Typer apps:
|
||||
This is the same information you saw on the section about <a href="https://typer.tiangolo.com/tutorial/commands/callback/" class="external-link" target="_blank">Commands - Typer Callback</a>, and it applies the same for sub-Typer apps:
|
||||
|
||||
```Python hl_lines="6 7 10 14 15 16"
|
||||
{!./src/subcommands/callback_override/tutorial003.py!}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
You read before how to create a program with <a href="https://typer.tiangolo.com/tutorial/commands/" target="_blank">Commands</a>.
|
||||
You read before how to create a program with <a href="https://typer.tiangolo.com/tutorial/commands/" class="external-link" target="_blank">Commands</a>.
|
||||
|
||||
Now we'll see how to create a *CLI program* with commands that have their own subcommands. Also known as command groups.
|
||||
|
||||
|
|
Loading…
Reference in a new issue