typer/docs
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
..
css Richify, add integrations with Rich everywhere (#419) 2022-07-12 16:45:43 +00:00
img 🔧 Add pre-commit config and formatting (#392) 2022-05-11 19:59:56 -05:00
js 🔧 Add pre-commit config and formatting (#392) 2022-05-11 19:59:56 -05:00
overrides 🔧 Add pre-commit config and formatting (#392) 2022-05-11 19:59:56 -05:00
tutorial Add support for custom types and parsers (updates/builds upon PR #443) (#583) 2023-05-01 03:03:26 -07:00
alternatives.md ✏ Fix broken plac link (#275) 2022-07-17 08:13:28 +00:00
contributing.md ⬆ Upgrade Isort to version 5.x.x (#137) 2020-07-09 22:09:53 +02:00
features.md 🔧 Add pre-commit config and formatting (#392) 2022-05-11 19:59:56 -05:00
help-typer.md 📝 Update docs about helping Typer (#547) 2023-02-03 18:51:55 +01:00
index.md 👷 Move from pytest-cov to coverage and Codecov to Smokeshow (#483) 2022-11-05 00:08:30 +01:00
release-notes.md 📝 Update release notes 2023-04-25 23:30:29 +00:00
typer-cli.md 📝 Add Optional to docs for CLI Arguments and Options with a None default (#131) 2020-08-16 14:01:19 +02:00