🔧 Update MkDocs to have titles in Markdown files instead of config (#913)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by GitHub · parent 9791e14 · Browse files · 59 files·+174 added−58 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
59 files+174 added−58 removed
- other:+174 added−58 removed
Provenance
- Commit
6b264ac- Tree
90f1398- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
9791e14
59 files changed+174 added−58 removed
modified:docs/tutorial/arguments/default.md+2 added
123456136 unmodified linesExpand all# CLI Arguments with Default
We can also use the same `typer.Argument()` to set a default value.
That way the *CLI argument* will be optional *and also* have a default value.
136 unmodified linesExpand allmodified:docs/tutorial/arguments/envvar.md+2 added
1+# CLI Arguments with Environment Variables2+3 You can also configure a *CLI argument* to read a value from an environment variable if it is not provided in the command line as a *CLI argument*.4 5 To do that, use the `envvar` parameter for `typer.Argument()`:6 174 unmodified linesmodified:docs/tutorial/arguments/help.md+2 added
1+# CLI Arguments with Help2+3 In the *First Steps* section you saw how to add help for a CLI app/command by adding it to a function's <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>.4 5 Here's how that last example looked like:6 449 unmodified linesmodified:docs/tutorial/arguments/index.md+2 added
12345# CLI Arguments
In the next few sections we'll see some ways to modify how *CLI arguments* work.
We'll create optional *CLI arguments*, we'll add integrated help for *CLI arguments*, etc.modified:docs/tutorial/arguments/optional.md+2 added
1+# Optional CLI Arguments2+3 We said before that *by default*:4 5 * *CLI options* are **optional**6 * *CLI arguments* are **required**247 unmodified linesmodified:docs/tutorial/arguments/other-uses.md+2 added
12345# Other uses
`typer.Argument()` has several other use cases. Such as for data validation, to enable other features, etc.
You will see about these use cases later in the docs.modified:docs/tutorial/commands/arguments.md+2 added
12345641 unmodified lines# Command CLI Arguments
The same way as with a CLI application with a single command, subcommands (or just "commands") can also have their own *CLI arguments*:
```Python hl_lines="7 12"{!../docs_src/commands/arguments/tutorial001.py!}41 unmodified linesmodified:docs/tutorial/commands/callback.md+2 added
1+# Typer Callback2+3 When you create an `app = typer.Typer()` it works as a group of commands.4 5 And you can create multiple commands with it.6 187 unmodified linesmodified:docs/tutorial/commands/context.md+2 added
1+# Using the Context2+3 When you create a **Typer** application it uses Click underneath. And every Click application has a special object called a <a href="https://click.palletsprojects.com/en/8.1.x/commands/#nested-handling-and-contexts" class="external-link" target="_blank">"Context"</a> that is normally hidden.4 5 But you can access the context by declaring a function parameter of type `typer.Context`.6 129 unmodified linesmodified:docs/tutorial/commands/help.md+2 added
1+# Command Help2+3 The same as before, you can add help for the commands in the docstrings and the *CLI options*.4 5 And the `typer.Typer()` application receives a parameter `help` that you can pass with the main help text for your CLI program:6 567 unmodified linesmodified:docs/tutorial/commands/index.md+2 added
1+# Commands2+3 We have seen how to create a CLI program with possibly several *CLI options* and *CLI arguments*.4 5 But **Typer** allows you to create CLI programs with several commands (also known as subcommands).6 280 unmodified linesmodified:docs/tutorial/commands/name.md+2 added
1+# Custom Command Name2+3 By default, the command names are generated from the function name.4 5 So, if your function is something like:6 52 unmodified linesmodified:docs/tutorial/commands/one-or-multiple.md+2 added
1+# One or Multiple Commands2+3 You might have noticed that if you create a single command, as in the first example:4 5 ```Python hl_lines="3 6 12"6 {!../docs_src/commands/index/tutorial001.py!}150 unmodified linesmodified:docs/tutorial/commands/options.md+2 added
1+# Command CLI Options2+3 Commands can also have their own *CLI options*.4 5 In fact, each command can have different *CLI arguments* and *CLI options*:6 113 unmodified linesmodified:docs/tutorial/multiple-values/arguments-with-multiple-values.md+2 added
1+# CLI Arguments with Multiple Values2+3 *CLI arguments* can also receive multiple values.4 5 You can define the type of a *CLI argument* using `typing.List`.6 94 unmodified linesmodified:docs/tutorial/multiple-values/index.md+2 added
1+# Multiple Values2+3 There are several ways to declare multiple values for *CLI options* and *CLI arguments*.4 5 We'll see them in the next short sections.modified:docs/tutorial/multiple-values/multiple-options.md+2 added
1+# Multiple CLI Options2+3 You can declare a *CLI option* that can be used multiple times, and then get all the values.4 5 For example, let's say you want to accept several users in a single execution.6 99 unmodified linesmodified:docs/tutorial/multiple-values/options-with-multiple-values.md+2 added
1+# CLI Options with Multiple Values2+3 You can also declare a *CLI option* that takes several values of different types.4 5 You can set the number of values and types to anything you want, but it has to be a fixed number of values.6 107 unmodified linesmodified:docs/tutorial/options/callback-and-context.md+2 added
1+# CLI Option Callback and Context2+3 In some occasions you might want to have some custom logic for a specific *CLI parameter* (for a *CLI option* or *CLI argument*) that is executed with the value received from the terminal.4 5 In those cases you can use a *CLI parameter* callback function.6 285 unmodified linesmodified:docs/tutorial/options/help.md+2 added
1+# CLI Options with Help2+3 You already saw how to add a help text for *CLI arguments* with the `help` parameter.4 5 Let's now do the same for *CLI options*:6 239 unmodified linesmodified:docs/tutorial/options/index.md+2 added
1+# CLI Options2+3 In the next short sections we will see how to modify *CLI options* using `typer.Option()`.4 5 `typer.Option()` works very similarly to `typer.Argument()`, but has some extra features that we'll see next.modified:docs/tutorial/options/name.md+2 added
1+# CLI Option Name2+3 By default **Typer** will create a *CLI option* name from the function parameter.4 5 So, if you have a function with:6 415 unmodified linesmodified:docs/tutorial/options/password.md+2 added
1+# Password CLI Option and Confirmation Prompt2+3 Apart from having a prompt, you can make a *CLI option* have a `confirmation_prompt=True`:4 5 //// tab | Python 3.7+6 85 unmodified linesmodified:docs/tutorial/options/prompt.md+2 added
1+# CLI Option Prompt2+3 It's also possible to, instead of just showing an error, ask for the missing value with `prompt=True`:4 5 //// tab | Python 3.7+6 138 unmodified linesmodified:docs/tutorial/options/required.md+2 added
1+# Required CLI Options2+3 We said before that *by default*:4 5 * *CLI options* are **optional**6 * *CLI arguments* are **required**83 unmodified linesmodified:docs/tutorial/options/version.md+2 added
1+# Version CLI Option, `is_eager`2+3 You could use a callback to implement a `--version` *CLI option*.4 5 It would show the version of your CLI program and then it would terminate it. Even before any other *CLI parameter* is processed.6 166 unmodified linesmodified:docs/tutorial/parameter-types/bool.md+2 added
1+# Boolean CLI Options2+3 We have seen some examples of *CLI options* with `bool`, and how **Typer** creates `--something` and `--no-something` automatically.4 5 But we can customize those names.6 253 unmodified linesmodified:docs/tutorial/parameter-types/custom-types.md+2 added
1+# Custom Types2+3 You can easily use your own custom types in your **Typer** applications.4 5 The way to do it is by providing a way to <abbr title="convert from some plain format, like the input text in the CLI, into Python objects">parse</abbr> input into your own types.6 44 unmodified linesmodified:docs/tutorial/parameter-types/datetime.md+2 added
1+# DateTime2+3 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>.4 5 Your function will receive a standard Python `datetime` object, and again, your editor will give you completion, etc.6 101 unmodified linesmodified:docs/tutorial/parameter-types/enum.md+2 added
1+# Enum - Choices2+3 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>:4 5 ```Python hl_lines="1 6 7 8 9 12 13"6 {!../docs_src/parameter_types/enum/tutorial001.py!}149 unmodified linesmodified:docs/tutorial/parameter-types/file.md+2 added
1+# File2+3 Apart from `Path` *CLI parameters* you can also declare some types of "files".4 5 /// tip6 346 unmodified linesmodified:docs/tutorial/parameter-types/index.md+2 added
1+# CLI Parameter Types2+3 You can use several data types for the *CLI options* and *CLI arguments*, and you can add data validation requirements too.4 5 ## Data conversion6 65 unmodified linesmodified:docs/tutorial/parameter-types/number.md+2 added
1+# Number2+3 You can define numeric validations with `max` and `min` values for `int` and `float` *CLI parameters*:4 5 //// tab | Python 3.7+6 199 unmodified linesmodified:docs/tutorial/parameter-types/path.md+2 added
1+# Path2+3 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>.4 5 This is what you would do for directory paths, file paths, etc:6 146 unmodified linesmodified:docs/tutorial/parameter-types/uuid.md+2 added
1+# UUID2+3 /// info4 5 A UUID is a <a href="https://en.wikipedia.org/wiki/Universally_unique_identifier" class="external-link" target="_blank">"Universally Unique Identifier"</a>.6 45 unmodified linesmodified:docs/tutorial/subcommands/add-typer.md+2 added
1+# Add Typer2+3 We'll start with the core idea.4 5 To add a `typer.Typer()` app inside of another.6 168 unmodified linesmodified:docs/tutorial/subcommands/callback-override.md+2 added
1+# Sub-Typer Callback Override2+3 When creating a **Typer** app you can define a callback function, it always executes and defines the *CLI arguments* and *CLI options* that go before a command.4 5 When adding a Typer app inside of another, the sub-Typer can also have its own callback.6 100 unmodified linesmodified:docs/tutorial/subcommands/index.md+2 added
1+# SubCommands - Command Groups2+3 You read before how to create a program with [Commands](../commands/index.md){.internal-link target=_blank}.4 5 Now we'll see how to create a *CLI program* with commands that have their own subcommands. Also known as command groups.6 35 unmodified linesmodified:docs/tutorial/subcommands/name-and-help.md+2 added
1+# SubCommand Name and Help2+3 When adding a Typer app to another we have seen how to set the `name` to use for the command.4 5 For example to set the command to `users`:6 467 unmodified linesmodified:docs/tutorial/subcommands/nested-subcommands.md+2 added
1+# Nested SubCommands2+3 We'll now see how these same ideas can be extended for deeply nested commands.4 5 Let's imagine that the same *CLI program* from the previous examples now needs to handle `lands`.6 297 unmodified linesmodified:docs/tutorial/subcommands/single-file.md+2 added
1+# SubCommands in a Single File2+3 In some cases, it's possible that your application code needs to live on a single file.4 5 You can still use the same ideas:6 144 unmodified linesmodified:docs/tutorial/app-dir.md+2 added
1+# CLI Application Directory2+3 You can get the application directory where you can, for example, save configuration files with `typer.get_app_dir()`:4 5 ```Python hl_lines="9"6 {!../docs_src/app_dir/tutorial001.py!}39 unmodified linesmodified:docs/tutorial/first-steps.md+2 added
1+# First Steps2+3 ## The simplest example4 5 The simplest **Typer** file could look like this:6 515 unmodified linesmodified:docs/tutorial/index.md+2 added
1+# Tutorial - User Guide2+3 ## Python types4 5 If you need a refresher about how to use Python type hints, check the first part of <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">FastAPI's Python types intro</a>.6 88 unmodified linesmodified:docs/tutorial/launch.md+2 added
1+# Launching Applications2+3 You can launch applications from your CLI program with `typer.launch()`.4 5 It will launch the appropriate application depending on the URL or file type you pass it:6 47 unmodified linesmodified:docs/tutorial/options-autocompletion.md+2 added
1+# CLI Option autocompletion2+3 As you have seen, apps built with **Typer** have completion in your shell that works when you create a Python package or using the `typer` command.4 5 It normally completes *CLI options*, *CLI arguments*, and subcommands (that you will learn about later).6 560 unmodified linesmodified:docs/tutorial/package.md+2 added
1+# Building a Package2+3 When you create a CLI program with **Typer** you probably want to create your own Python package.4 5 That's what allows your users to install it and have it as an independent program that they can use in their terminal.6 769 unmodified linesmodified:docs/tutorial/printing.md+2 added
1+# Printing and Colors2+3 You can use the normal `print()` to show information on the screen:4 5 ```Python hl_lines="5"6 {!../docs_src/first_steps/tutorial001.py!}292 unmodified linesmodified:docs/tutorial/progressbar.md+2 added
1+# Progress Bar2+3 If you are executing an operation that can take some time, you can inform it to the user. 🤓4 5 ## Progress Bar6 244 unmodified linesmodified:docs/tutorial/prompt.md+2 added
1+# Ask with Prompt2+3 When you need to ask the user for info interactively you should normally use [*CLI Option*s with Prompt](options/prompt.md){.internal-link target=_blank}, because they allow using the CLI program in a non-interactive way (for example, a Bash script could use it).4 5 But if you absolutely need to ask for interactive information without using a *CLI option*, you can use `typer.prompt()`:6 96 unmodified linesmodified:docs/tutorial/terminating.md+2 added
1+# Terminating2+3 There are some cases where you might want to terminate a command at some point, and stop all subsequent execution.4 5 It could be that your code determined that the program completed successfully, or it could be an operation aborted.6 120 unmodified linesmodified:docs/tutorial/testing.md+2 added
1+# Testing2+3 Testing **Typer** applications is very easy with <a href="https://docs.pytest.org/en/latest/" class="external-link" target="_blank">pytest</a>.4 5 Let's say you have an application `app/main.py` with:6 242 unmodified linesmodified:docs/tutorial/using-click.md+2 added
1+# Using Click2+3 /// warning4 5 This is a more advanced topic, if you are starting with **Typer**, feel free to skip it.6 195 unmodified linesmodified:docs/alternatives.md+2 added
1+# Alternatives, Inspiration and Comparisons2+3 What inspired **Typer**, how it compares to other alternatives and what it learned from them.4 5 ## Intro6 97 unmodified linesmodified:docs/contributing.md+2 added
1+# Development - Contributing2+3 First, you might want to see the basic ways to [help Typer and get help](help-typer.md){.internal-link target=_blank}.4 5 ## Developing6 244 unmodified linesmodified:docs/features.md+2 added
1+# Features2+3 ## Design based on **FastAPI**4 5 <a href="https://fastapi.tiangolo.com" target="_blank"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" style="width: 20%;"></a>6 87 unmodified linesmodified:docs/help-typer.md+2 added
1+# Help Typer - Get Help2+3 Are you liking **Typer**?4 5 Would you like to help Typer, other users, and the author?6 243 unmodified linesmodified:docs/release-notes.md+2 added
1+# Release Notes2+3 ## Latest Changes4 5 ### Features6 580 unmodified linesmodified:mkdocs.yml+58 added-58 removed
50 unmodified lines51 typer-cli.md: tutorial/typer-command.md52 53 nav:54 - Typer: index.md55- - Features: features.md55+ - features.md56 - Tutorial - User Guide:57- - Tutorial - User Guide - Intro: tutorial/index.md58- - First Steps: tutorial/first-steps.md59- - Printing and Colors: tutorial/printing.md60- - Terminating: tutorial/terminating.md57+ - tutorial/index.md58+ - tutorial/first-steps.md59+ - tutorial/printing.md60+ - tutorial/terminating.md61 - CLI Arguments:62- - CLI Arguments Intro: tutorial/arguments/index.md63- - Optional CLI Arguments: tutorial/arguments/optional.md64- - CLI Arguments with Default: tutorial/arguments/default.md65- - CLI Arguments with Help: tutorial/arguments/help.md66- - CLI Arguments with Environment Variables: tutorial/arguments/envvar.md67- - Other uses: tutorial/arguments/other-uses.md62+ - tutorial/arguments/index.md63+ - tutorial/arguments/optional.md64+ - tutorial/arguments/default.md65+ - tutorial/arguments/help.md66+ - tutorial/arguments/envvar.md67+ - tutorial/arguments/other-uses.md68 - CLI Options:69- - CLI Options Intro: tutorial/options/index.md70- - CLI Options with Help: tutorial/options/help.md71- - Required CLI Options: tutorial/options/required.md72- - CLI Option Prompt: tutorial/options/prompt.md73- - Password CLI Option and Confirmation Prompt: tutorial/options/password.md74- - CLI Option Name: tutorial/options/name.md75- - CLI Option Callback and Context: tutorial/options/callback-and-context.md76- - Version CLI Option, is_eager: tutorial/options/version.md69+ - tutorial/options/index.md70+ - tutorial/options/help.md71+ - tutorial/options/required.md72+ - tutorial/options/prompt.md73+ - tutorial/options/password.md74+ - tutorial/options/name.md75+ - tutorial/options/callback-and-context.md76+ - tutorial/options/version.md77 - Commands:78- - Commands Intro: tutorial/commands/index.md79- - Command CLI Arguments: tutorial/commands/arguments.md80- - Command CLI Options: tutorial/commands/options.md81- - Command Help: tutorial/commands/help.md82- - Custom Command Name: tutorial/commands/name.md83- - Typer Callback: tutorial/commands/callback.md84- - One or Multiple Commands: tutorial/commands/one-or-multiple.md85- - Using the Context: tutorial/commands/context.md86- - CLI Option autocompletion: tutorial/options-autocompletion.md78+ - tutorial/commands/index.md79+ - tutorial/commands/arguments.md80+ - tutorial/commands/options.md81+ - tutorial/commands/help.md82+ - tutorial/commands/name.md83+ - tutorial/commands/callback.md84+ - tutorial/commands/one-or-multiple.md85+ - tutorial/commands/context.md86+ - tutorial/options-autocompletion.md87 - CLI Parameter Types:88- - CLI Parameter Types Intro: tutorial/parameter-types/index.md89- - Number: tutorial/parameter-types/number.md90- - Boolean CLI Options: tutorial/parameter-types/bool.md91- - UUID: tutorial/parameter-types/uuid.md92- - DateTime: tutorial/parameter-types/datetime.md93- - Enum - Choices: tutorial/parameter-types/enum.md94- - Path: tutorial/parameter-types/path.md95- - File: tutorial/parameter-types/file.md96- - Custom Types: tutorial/parameter-types/custom-types.md88+ - tutorial/parameter-types/index.md89+ - tutorial/parameter-types/number.md90+ - tutorial/parameter-types/bool.md91+ - tutorial/parameter-types/uuid.md92+ - tutorial/parameter-types/datetime.md93+ - tutorial/parameter-types/enum.md94+ - tutorial/parameter-types/path.md95+ - tutorial/parameter-types/file.md96+ - tutorial/parameter-types/custom-types.md97 - SubCommands - Command Groups:98- - SubCommands - Command Groups - Intro: tutorial/subcommands/index.md99- - Add Typer: tutorial/subcommands/add-typer.md100- - SubCommands in a Single File: tutorial/subcommands/single-file.md101- - Nested SubCommands: tutorial/subcommands/nested-subcommands.md102- - Sub-Typer Callback Override: tutorial/subcommands/callback-override.md103- - SubCommand Name and Help: tutorial/subcommands/name-and-help.md98+ - tutorial/subcommands/index.md99+ - tutorial/subcommands/add-typer.md100+ - tutorial/subcommands/single-file.md101+ - tutorial/subcommands/nested-subcommands.md102+ - tutorial/subcommands/callback-override.md103+ - tutorial/subcommands/name-and-help.md104 - Multiple Values:105- - Multiple Values Intro: tutorial/multiple-values/index.md106- - Multiple CLI Options: tutorial/multiple-values/multiple-options.md107- - CLI Options with Multiple Values: tutorial/multiple-values/options-with-multiple-values.md108- - CLI Arguments with Multiple Values: tutorial/multiple-values/arguments-with-multiple-values.md109- - Ask with Prompt: tutorial/prompt.md110- - Progress Bar: tutorial/progressbar.md111- - CLI Application Directory: tutorial/app-dir.md112- - Launching Applications: tutorial/launch.md113- - Testing: tutorial/testing.md114- - Using Click: tutorial/using-click.md115- - Building a Package: tutorial/package.md105+ - tutorial/multiple-values/index.md106+ - tutorial/multiple-values/multiple-options.md107+ - tutorial/multiple-values/options-with-multiple-values.md108+ - tutorial/multiple-values/arguments-with-multiple-values.md109+ - tutorial/prompt.md110+ - tutorial/progressbar.md111+ - tutorial/app-dir.md112+ - tutorial/launch.md113+ - tutorial/testing.md114+ - tutorial/using-click.md115+ - tutorial/package.md116 - tutorial/exceptions.md117 - tutorial/typer-command.md118- - Alternatives, Inspiration and Comparisons: alternatives.md119- - Help Typer - Get Help: help-typer.md120- - Development - Contributing: contributing.md121- - Release Notes: release-notes.md118+ - alternatives.md119+ - help-typer.md120+ - contributing.md121+ - release-notes.md122 123 markdown_extensions:124 toc:125 permalink: true49 unmodified lines