typer/docs/tutorial
John Purviance 3e37e01979
Add support for custom types and parsers (updates/builds upon PR #443) (#583)
* Support custom parameter types

While most CLI parameters are strings, ints, etc, we sometimes need custom
types.

Currently typer has no support for it (See #77), and while there are a few hacks, the
likely solution is to add a 'str' argument and parse it inside the main function.

This PR adds support for custom types in 3 different ways:
- Manually specifying a `click_type`
- Manually specifying a `parse` function
- Using a Callable type annotation (It is very common for types to have a string constructor, like `int("1")`)

* Document how to parse custom objects with Typer.

Typer supports parsing of cutom types with:
- A user provided parser class
- A click custom type parser

* 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

* 📝 Tweak and simplify docs

*  Tweak tests to run scripts and remove pragma: nocover in examples

* 📝 Tweak examples for docs, add types and remove # pragma: nocover

* ♻️ Tweak implementation checking for parser and Click type

---------

Co-authored-by: Paulo Costa <me@paulo.costa.nom.br>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2023-05-01 03:03:26 -07:00
..
arguments Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
commands Make typer.run() not add completion scripts by default, it only makes sense in installed apps (#488) 2022-11-05 16:13:37 +00:00
multiple-values 📝 Update docs with the new --help argument (#135) 2020-08-16 14:19:40 +02:00
options Make typer.run() not add completion scripts by default, it only makes sense in installed apps (#488) 2022-11-05 16:13:37 +00:00
parameter-types Add support for custom types and parsers (updates/builds upon PR #443) (#583) 2023-05-01 03:03:26 -07:00
subcommands 🔧 Add pre-commit config and formatting (#392) 2022-05-11 19:59:56 -05:00
app-dir.md ⬆ Upgrade Isort to version 5.x.x (#137) 2020-07-09 22:09:53 +02:00
exceptions.md Refactor and document handling pretty exceptions (#422) 2022-07-12 21:06:51 +02:00
first-steps.md ✏ Update first-steps.md, clarify distinction between parameter and argument (#176) 2022-07-17 08:15:44 +00:00
index.md Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
launch.md 🔧 Add pre-commit config and formatting (#392) 2022-05-11 19:59:56 -05:00
options-autocompletion.md Make typer.run() not add completion scripts by default, it only makes sense in installed apps (#488) 2022-11-05 16:13:37 +00:00
package.md ✏️ Add quotes to package name that includes brackets in docs (#475) 2022-11-06 15:12:01 +00:00
printing.md Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
progressbar.md 📝 Add docs for using Rich with Typer (#421) 2022-07-12 18:38:50 +00:00
prompt.md 📝 Add docs for using Rich with Typer (#421) 2022-07-12 18:38:50 +00:00
terminating.md ✏ Fix typo in docs/tutorial/terminating.md (#382) 2022-05-12 19:13:47 +00:00
testing.md 📝 Clarify testing documentation about checking stderr (#335) 2022-07-02 17:36:25 +00:00
using-click.md Add support for Click 8 while keeping compatibility with Click 7 (#317) 2021-08-30 09:57:12 +02:00