File: launch.md

package info (click to toggle)
typer 0.19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: python: 16,702; javascript: 280; sh: 28; makefile: 27
file content (49 lines) | stat: -rw-r--r-- 954 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Launching Applications

You can launch applications from your CLI program with `typer.launch()`.

It will launch the appropriate application depending on the URL or file type you pass it:

{* docs_src/launch/tutorial001.py hl[6] *}

Check it:

<div class="termy">

```console
$ python main.py

Opening Typer docs

// Opens browser with Typer's docs
```

</div>

## Locating a file

You can also make the operating system open the file browser indicating where a file is located with `locate=True`:

{* docs_src/launch/tutorial002.py hl[17] *}

/// tip

The rest of the code in this example is just making sure the app directory exists and creating the config file.

But the most important part is the `typer.launch(config_file_str, locate=True)` with the argument `locate=True`.

///

Check it:

<div class="termy">

```console
$ python main.py

Opening config directory

// Opens a file browser indicating where the config file is located
```

</div>