Skip to content
Myr

📝 Tweak docs, Custom Types path, main page and READAME colors, broken links (#588)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* 📝 Tweak name for Custom Types * ✏️ Fix broken internal links in CLI Option autocompletion * 📝 Update main page docs, remove colors as that renders badly in README * 📝 Update README, sync with index.md, remove colors for GitHub and PyPI

authored by Sebastián Ramírez · committed by GitHub · parent 27d0fde · Browse files · 6 files+131 added−149 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+131 added−149 removed

  • other:+131 added−149 removed

6 files+131 added−149 removed

deleted:docs/tutorial/parameter-types/custom_types.md-27 removed
added:docs/tutorial/parameter-types/custom-types.md+27 added
modified:docs/tutorial/options-autocompletion.md+3 added-3 removed
8 unmodified lines
9Before checking how to provide custom completions, let's check again how it works.1011After installing completion (for your own Python package or for **Typer CLI**), when you use your CLI program and start adding a *CLI option* with `--` an then hit <kbd>TAB</kbd>, your shell will show you the available *CLI options* (the same for *CLI arguments*, etc).1213To check it quickly without creating a new Python package, install [Typer CLI](../../typer-cli.md){.internal-link target=_blank}.13To check it quickly without creating a new Python package, install [Typer CLI](../typer-cli.md){.internal-link target=_blank}.1415Then let's create small example program:1617```Python
29 unmodified lines
47## Custom completion for values4849Right now we get completion for the *CLI option* names, but not for the values.5051We can provide completion for the values creating an `autocompletion` function, similar to the `callback` functions from [CLI Option Callback and Context](./callback-and-context.md){.internal-link target=_blank}:51We can provide completion for the values creating an `autocompletion` function, similar to the `callback` functions from [CLI Option Callback and Context](./options/callback-and-context.md){.internal-link target=_blank}:5253```Python hl_lines="4-5 14"54{!../docs_src/options_autocompletion/tutorial002.py!}55```
216 unmodified lines
272273### Printing to "standard error"274275!!! tip276 If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](../printing.md#standard-output-and-standard-error){.internal-link target=_blank}.276 If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](./printing.md#standard-output-and-standard-error){.internal-link target=_blank}.277278The completion system only reads from "standard output", so, printing to "standard error" won't break completion. 🚀279280You can print to "standard error" with a **Rich** `Console(stderr=True)`.
86 unmodified lines
modified:docs/index.md+50 added-59 removed
91 unmodified lines
92// Run your application93$ python main.py9495// You get a nice error, you are missing NAME96<font color="#F4BF75">Usage: </font>main.py [OPTIONS] NAME97<font color="#A5A5A1">Try </font><font color="#44919F">&apos;main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">&apos;</font><font color="#A5A5A1"> for help.</font>98<font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>99<font color="#F92672">│</font> Missing argument &apos;NAME&apos;. <font color="#F92672">│</font>100<font color="#F92672">╰───────────────────────────────────────────────────╯</font>96Usage: main.py [OPTIONS] NAME97Try 'main.py --help' for help.98╭─ Error ───────────────────────────────────────────╮99│ Missing argument 'NAME'. │100╰───────────────────────────────────────────────────╯101102103// You get a --help for free104$ python main.py --help105106<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] NAME </b>107<b> </b>108<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────╮</font>109<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │110<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>111<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────╮</font>112<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--install-completion</b></font> Install completion │113<font color="#A5A5A1">│ for the current │</font>114<font color="#A5A5A1">│ shell. │</font>115<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--show-completion</b></font> Show completion for │116<font color="#A5A5A1">│ the current shell, │</font>117<font color="#A5A5A1">│ to copy it or │</font>118<font color="#A5A5A1">│ customize the │</font>119<font color="#A5A5A1">│ installation. │</font>120<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message │121<font color="#A5A5A1">│ and exit. │</font>122<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>106Usage: main.py [OPTIONS] NAME107124// When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion108╭─ Arguments ───────────────────────────────────────╮109│ * name TEXT [default: None] [required] |110╰───────────────────────────────────────────────────╯111╭─ Options ─────────────────────────────────────────╮112│ --help Show this message and exit. │113╰───────────────────────────────────────────────────╯114115// Now pass the NAME argument116$ python main.py Camila117
56 unmodified lines
174175```console176$ python main.py --help177189<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] COMMAND [ARGS]... </b>190<b> </b>191<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────╮</font>192<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--install-completion</b></font> Install completion │193<font color="#A5A5A1">│ for the current │</font>194<font color="#A5A5A1">│ shell. │</font>195<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--show-completion</b></font> Show completion for │196<font color="#A5A5A1">│ the current shell, │</font>197<font color="#A5A5A1">│ to copy it or │</font>198<font color="#A5A5A1">│ customize the │</font>199<font color="#A5A5A1">│ installation. │</font>200<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message │201<font color="#A5A5A1">│ and exit. │</font>202<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>203<font color="#A5A5A1">╭─ Commands ────────────────────────────────────────╮</font>204<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>goodbye </b></font> │205<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>hello </b></font> │206<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>178 Usage: main.py [OPTIONS] COMMAND [ARGS]...179180╭─ Options ─────────────────────────────────────────╮181│ --install-completion Install completion │182│ for the current │183│ shell. │184│ --show-completion Show completion for │185│ the current shell, │186│ to copy it or │187│ customize the │188│ installation. │189│ --help Show this message │190│ and exit. │191╰───────────────────────────────────────────────────╯192╭─ Commands ────────────────────────────────────────╮193│ goodbye │194│ hello │195╰───────────────────────────────────────────────────╯196197// When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion198199// You have 2 subcommands (the 2 functions): goodbye and hello200```201202</div>
4 unmodified lines
207208```console209$ python main.py hello --help210220<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py hello [OPTIONS] NAME </b>221<b> </b>222<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────╮</font>223<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │224<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>225<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────╮</font>226<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and exit. │227<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>211 Usage: main.py hello [OPTIONS] NAME212213╭─ Arguments ───────────────────────────────────────╮214│ * name TEXT [default: None] [required] │215╰───────────────────────────────────────────────────╯216╭─ Options ─────────────────────────────────────────╮217│ --help Show this message and exit. │218╰───────────────────────────────────────────────────╯219```220221</div>222
3 unmodified lines
226227```console228$ python main.py goodbye --help229239<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py goodbye [OPTIONS] NAME </b>240<b> </b>241<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────╮</font>242<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │243<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>244<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────╮</font>245<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--formal</b></font> <font color="#AE81FF"><b>--no-formal</b></font> [default: no-formal] │246<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message │247<font color="#A5A5A1">│ and exit. │</font>248<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>230 Usage: main.py goodbye [OPTIONS] NAME231232╭─ Arguments ───────────────────────────────────────╮233│ * name TEXT [default: None] [required] │234╰───────────────────────────────────────────────────╯235╭─ Options ─────────────────────────────────────────╮236│ --formal --no-formal [default: no-formal] │237│ --help Show this message │238│ and exit. │239╰───────────────────────────────────────────────────╯240241// Automatic --formal and --no-formal for the bool option 🎉242```243244</div>
73 unmodified lines
modified:mkdocs.yml+1 added-1 removed
modified:README.md+50 added-59 removed
91 unmodified lines
92// Run your application93$ python main.py9495// You get a nice error, you are missing NAME96<font color="#F4BF75">Usage: </font>main.py [OPTIONS] NAME97<font color="#A5A5A1">Try </font><font color="#44919F">&apos;main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">&apos;</font><font color="#A5A5A1"> for help.</font>98<font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>99<font color="#F92672">│</font> Missing argument &apos;NAME&apos;. <font color="#F92672">│</font>100<font color="#F92672">╰───────────────────────────────────────────────────╯</font>96Usage: main.py [OPTIONS] NAME97Try 'main.py --help' for help.98╭─ Error ───────────────────────────────────────────╮99│ Missing argument 'NAME'. │100╰───────────────────────────────────────────────────╯101102103// You get a --help for free104$ python main.py --help105106<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] NAME </b>107<b> </b>108<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────╮</font>109<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │110<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>111<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────╮</font>112<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--install-completion</b></font> Install completion │113<font color="#A5A5A1">│ for the current │</font>114<font color="#A5A5A1">│ shell. │</font>115<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--show-completion</b></font> Show completion for │116<font color="#A5A5A1">│ the current shell, │</font>117<font color="#A5A5A1">│ to copy it or │</font>118<font color="#A5A5A1">│ customize the │</font>119<font color="#A5A5A1">│ installation. │</font>120<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message │121<font color="#A5A5A1">│ and exit. │</font>122<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>106Usage: main.py [OPTIONS] NAME107124// When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion108╭─ Arguments ───────────────────────────────────────╮109│ * name TEXT [default: None] [required] |110╰───────────────────────────────────────────────────╯111╭─ Options ─────────────────────────────────────────╮112│ --help Show this message and exit. │113╰───────────────────────────────────────────────────╯114115// Now pass the NAME argument116$ python main.py Camila117
56 unmodified lines
174175```console176$ python main.py --help177189<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] COMMAND [ARGS]... </b>190<b> </b>191<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────╮</font>192<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--install-completion</b></font> Install completion │193<font color="#A5A5A1">│ for the current │</font>194<font color="#A5A5A1">│ shell. │</font>195<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--show-completion</b></font> Show completion for │196<font color="#A5A5A1">│ the current shell, │</font>197<font color="#A5A5A1">│ to copy it or │</font>198<font color="#A5A5A1">│ customize the │</font>199<font color="#A5A5A1">│ installation. │</font>200<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message │201<font color="#A5A5A1">│ and exit. │</font>202<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>203<font color="#A5A5A1">╭─ Commands ────────────────────────────────────────╮</font>204<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>goodbye </b></font> │205<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>hello </b></font> │206<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>178 Usage: main.py [OPTIONS] COMMAND [ARGS]...179180╭─ Options ─────────────────────────────────────────╮181│ --install-completion Install completion │182│ for the current │183│ shell. │184│ --show-completion Show completion for │185│ the current shell, │186│ to copy it or │187│ customize the │188│ installation. │189│ --help Show this message │190│ and exit. │191╰───────────────────────────────────────────────────╯192╭─ Commands ────────────────────────────────────────╮193│ goodbye │194│ hello │195╰───────────────────────────────────────────────────╯196197// When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion198199// You have 2 subcommands (the 2 functions): goodbye and hello200```201202</div>
4 unmodified lines
207208```console209$ python main.py hello --help210220<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py hello [OPTIONS] NAME </b>221<b> </b>222<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────╮</font>223<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │224<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>225<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────╮</font>226<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and exit. │227<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>211 Usage: main.py hello [OPTIONS] NAME212213╭─ Arguments ───────────────────────────────────────╮214│ * name TEXT [default: None] [required] │215╰───────────────────────────────────────────────────╯216╭─ Options ─────────────────────────────────────────╮217│ --help Show this message and exit. │218╰───────────────────────────────────────────────────╯219```220221</div>222
3 unmodified lines
226227```console228$ python main.py goodbye --help229239<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py goodbye [OPTIONS] NAME </b>240<b> </b>241<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────╮</font>242<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │243<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>244<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────╮</font>245<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--formal</b></font> <font color="#AE81FF"><b>--no-formal</b></font> [default: no-formal] │246<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message │247<font color="#A5A5A1">│ and exit. │</font>248<font color="#A5A5A1">╰───────────────────────────────────────────────────╯</font>230 Usage: main.py goodbye [OPTIONS] NAME231232╭─ Arguments ───────────────────────────────────────╮233│ * name TEXT [default: None] [required] │234╰───────────────────────────────────────────────────╯235╭─ Options ─────────────────────────────────────────╮236│ --formal --no-formal [default: no-formal] │237│ --help Show this message │238│ and exit. │239╰───────────────────────────────────────────────────╯240241// Automatic --formal and --no-formal for the bool option 🎉242```243244</div>
73 unmodified lines