Skip to content

Commit 766f222

Browse files
committed
cli
1 parent 8c631f1 commit 766f222

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

taskbadger/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .integrations import Action, EmailIntegration
2-
from .sdk import Task, init, update_task
2+
from .sdk import Task, init, init_from_env, update_task

taskbadger/cli.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import subprocess
2+
from typing import List
3+
4+
import typer
5+
6+
import taskbadger as tb
7+
8+
app = typer.Typer()
9+
10+
tb.init_from_env()
11+
12+
13+
@app.command()
14+
def monitor(name: str, command: List[str] = typer.Argument(None)):
15+
task = tb.Task.create(name)
16+
result = subprocess.run(command, env={"TASKBADGER_TASK_ID": task.id})
17+
if result.returncode != 0:
18+
task.success()
19+
else:
20+
task.error(data={"return_code": result.returncode})
21+
22+
23+
if __name__ == "__main__":
24+
app()

taskbadger/sdk.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dataclasses
2+
import os
23
from typing import List
34

45
from _contextvars import ContextVar
@@ -14,6 +15,14 @@
1415
_local = ContextVar("taskbadger_client")
1516

1617

18+
def init_from_env():
19+
_init(
20+
os.environ["TASKBADGER_ORG"],
21+
os.environ["TASKBADGER_PROJECT"],
22+
os.environ["TASKBADGER_TOKEN"],
23+
)
24+
25+
1726
def init(organization_slug: str, project_slug: str, token: str):
1827
_init("https://taskbadger.net", organization_slug, project_slug, token)
1928

0 commit comments

Comments
 (0)