docs: think more about design

This commit is contained in:
Daylin Morgan 2024-10-25 14:27:00 -05:00
parent 1b28e6c93d
commit 4ca3cabc53
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -12,12 +12,14 @@ basic design:
```python ```python
from swydd import taks, option, cli from swydd import taks, option, cli
@task @task
@option("program", "name of program to compile") @option("program", "name of program to compile")
def build(program: str = "hello"): def build(program: str = "hello"):
"""build a program""" """build a program"""
sub < f"gcc -o {program} {program}.c" sub < f"gcc -o {program} {program}.c"
cli() cli()
``` ```
@ -32,11 +34,10 @@ cli()
```python ```python
@task @task
def pipe_commands() def pipe_commands():
"""run pre-commit (and mypy)""" """run pre-commit (and mypy)"""
p = Pipe(Exec("find . -name file"), Exec("grep 'pattern'")).get() p = Pipe(Exec("find . -name file"), Exec("grep 'pattern'")).get()
print(p.stdout) print(p.stdout)
``` ```
Made even simpler with operator overloading: Made even simpler with operator overloading:
@ -61,12 +62,23 @@ def run_commands():
print(stdout) print(stdout)
``` ```
## Handling a DAG
```python
@task
@needs("src/a-file.txt")
@targets("build/output.txt")
def build():
"""build step with a dependency"""
lines = asset("src/a-filter.txt").read().splitlines()
# or lines = ctx.needs[0].read().splitlines()
ctx.targets.output.write("\n".join([f"{i}: {line}" for i, line in enumerate(lines)]))
```
## Internal CLI ## Internal CLI
```sh ```sh
./tasks.py _ swydd-subcmd ./tasks.py +swydd --version # <- current favorite (use a none valid function name to possibly prevent overlap)
# vs
./tasks.py _swydd-subcmd
# or
./tasks.py +swydd subcmd # <- current favorite (use a none valid function name to possibly prevent overlap)
``` ```