typer/docs_src
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
..
app_dir Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
arguments Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
commands Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
exceptions Refactor and document handling pretty exceptions (#422) 2022-07-12 21:06:51 +02:00
first_steps Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
launch Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
multiple_values Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00: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
options_autocompletion 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
printing Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
progressbar 📝 Add docs for using Rich with Typer (#421) 2022-07-12 18:38:50 +00:00
prompt 📝 Add docs for using Rich with Typer (#421) 2022-07-12 18:38:50 +00:00
subcommands Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
terminating Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
testing Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
using_click Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00