From 32436f0b1ada9d27f2f7cae0498064984789976b Mon Sep 17 00:00:00 2001 From: Rupsi Kaushik Date: Sun, 16 Aug 2020 08:01:19 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20Optional=20to=20docs=20for?= =?UTF-8?q?=20CLI=20Arguments=20and=20Options=20with=20a=20None=20default?= =?UTF-8?q?=20(#131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastián Ramírez --- docs/tutorial/options/name.md | 4 ++-- docs/tutorial/options/version.md | 6 +++--- docs/tutorial/parameter-types/bool.md | 2 +- docs/tutorial/parameter-types/path.md | 2 +- docs/typer-cli.md | 6 ++++-- docs_src/multiple_values/multiple_options/tutorial001.py | 4 ++-- docs_src/options/version/tutorial001.py | 6 +++++- docs_src/options/version/tutorial002.py | 6 +++++- docs_src/options/version/tutorial003.py | 4 +++- docs_src/parameter_types/bool/tutorial002.py | 4 +++- docs_src/parameter_types/path/tutorial001.py | 3 ++- docs_src/testing/app01/main.py | 4 +++- 12 files changed, 34 insertions(+), 17 deletions(-) diff --git a/docs/tutorial/options/name.md b/docs/tutorial/options/name.md index e25e1a9..cf037b8 100644 --- a/docs/tutorial/options/name.md +++ b/docs/tutorial/options/name.md @@ -3,14 +3,14 @@ By default **Typer** will create a *CLI option* name from the function parameter So, if you have a function with: ```Python -def main(user_name: str = None): +def main(user_name: Optional[str] = None): pass ``` or ```Python -def main(user_name: str = typer.Option(None)): +def main(user_name: Optional[str] = typer.Option(None)): pass ``` diff --git a/docs/tutorial/options/version.md b/docs/tutorial/options/version.md index b94ccf7..4002669 100644 --- a/docs/tutorial/options/version.md +++ b/docs/tutorial/options/version.md @@ -6,7 +6,7 @@ It would show the version of your CLI program and then it would terminate it. Ev Let's see a first version of how it could look like: -```Python hl_lines="6 7 8 9 14" +```Python hl_lines="8-11 16-18" {!../docs_src/options/version/tutorial001.py!} ``` @@ -57,7 +57,7 @@ Awesome CLI Version: 0.1.0 But now let's say that the `--name` *CLI option* that we declared before `--version` is required, and it has a callback that could exit the program: -```Python hl_lines="12 13 14 18" +```Python hl_lines="14-16 21-23" {!../docs_src/options/version/tutorial002.py!} ``` @@ -89,7 +89,7 @@ For those cases, we can mark a *CLI parameter* (a *CLI option* or *CLI argument* That will tell **Typer** (actually Click) that it should process this *CLI parameter* before the others: -```Python hl_lines="21" +```Python hl_lines="22-24" {!../docs_src/options/version/tutorial003.py!} ``` diff --git a/docs/tutorial/parameter-types/bool.md b/docs/tutorial/parameter-types/bool.md index a0d0892..26629ac 100644 --- a/docs/tutorial/parameter-types/bool.md +++ b/docs/tutorial/parameter-types/bool.md @@ -60,7 +60,7 @@ We might want to instead have `--accept` and `--reject`. We can do that by passing a single `str` with the 2 names for the `bool` *CLI option* separated by `/`: -```Python hl_lines="4" +```Python hl_lines="6" {!../docs_src/parameter_types/bool/tutorial002.py!} ``` diff --git a/docs/tutorial/parameter-types/path.md b/docs/tutorial/parameter-types/path.md index 89ae996..887ab37 100644 --- a/docs/tutorial/parameter-types/path.md +++ b/docs/tutorial/parameter-types/path.md @@ -2,7 +2,7 @@ You can declare a *CLI parameter* to be a standard Python