diff --git a/docs/src/parameter_types/path/tutorial001.py b/docs/src/parameter_types/path/tutorial001.py
index 97f94edcd0..d90f7af991 100644
--- a/docs/src/parameter_types/path/tutorial001.py
+++ b/docs/src/parameter_types/path/tutorial001.py
@@ -3,7 +3,10 @@
import typer
-def main(config: Path = typer.Option(...)):
+def main(config: Path = typer.Option(None)):
+ if config is None:
+ typer.echo("No config file")
+ raise typer.Abort()
if config.is_file():
text = config.read_text()
typer.echo(f"Config file contents: {text}")
diff --git a/docs/tutorial/parameter-types/path.md b/docs/tutorial/parameter-types/path.md
index 4fdfb88064..8ca2bea43c 100644
--- a/docs/tutorial/parameter-types/path.md
+++ b/docs/tutorial/parameter-types/path.md
@@ -13,6 +13,13 @@ Check it:
```console
+// No config
+$ python main.py
+
+No config file
+Aborted!
+
+// Pass a config that doesn't exist
$ python main.py --config config.txt
The config doesn't exist
@@ -42,7 +49,10 @@ You can perform several validations for `Path` *CLI parameters*:
* `dir_okay`: controls if a directory is a possible value.
* `writable`: if true, a writable check is performed.
* `readable`: if true, a readable check is performed.
-* `resolve_path`: if this is true, then the path is fully resolved before the value is passed onwards. This means that it’s absolute and symlinks are resolved. It will not expand a tilde-prefix, as this is supposed to be done by the shell only.
+* `resolve_path`: if this is true, then the path is fully resolved before the value is passed onwards. This means that it’s absolute and
symlinks are resolved.
+
+!!! note "Technical Details"
+ It will not expand a tilde-prefix (something with `~`, like `~/Documents/`), as this is supposed to be done by the shell only.
!!! tip
All these parameters come directly from
Click.
diff --git a/tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py b/tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py
index 88affcfdd1..9ef0cec4c5 100644
--- a/tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py
+++ b/tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py
@@ -14,6 +14,13 @@
config_file = Path("./config.txt")
+def test_no_path():
+ result = runner.invoke(app)
+ assert result.exit_code == 1
+ assert "No config file" in result.output
+ assert "Aborted!" in result.output
+
+
def test_not_exists():
if config_file.exists(): # pragma no cover
config_file.unlink()