-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsay.py
37 lines (26 loc) · 871 Bytes
/
say.py
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
"""
Simple example using cowsay.
Try with::
$ python say.py "Simple is better than complex"
"""
import sys
import anyio
import dagger
from rich.console import Console
console = Console()
async def main(args: list[str]):
with console.status("Hold on..."):
async with dagger.Connection() as client:
# build container with cowsay entrypoint
# note: this is reusable, no request is made to the server
ctr = (
client.container()
.from_("python:alpine")
.with_exec(["pip", "install", "cowsay"])
.with_entrypoint(["cowsay"])
)
# run cowsay with requested message
# note: queries are executed only on coroutines
result = await ctr.with_exec(args).stdout()
print(result)
anyio.run(main, sys.argv[1:])