Zalohovani vsech podstatnych souboru
This commit is contained in:
61
skills/detach/scripts/read-task.py
Executable file
61
skills/detach/scripts/read-task.py
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env -S uv run --script
|
||||
# /// script
|
||||
# requires-python = ">=3.11"
|
||||
# dependencies = []
|
||||
# ///
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from tasks_common import FILENAME_RE, TASKS, format_result
|
||||
|
||||
|
||||
def completed_files() -> list[Path]:
|
||||
paths = []
|
||||
for d in ("done", "failed"):
|
||||
p = TASKS / d
|
||||
if p.exists():
|
||||
paths.extend(p.glob("*.md"))
|
||||
return sorted(paths, key=lambda f: f.name, reverse=True)
|
||||
|
||||
|
||||
def find_matches(identifier: str) -> list[Path]:
|
||||
if not identifier:
|
||||
done = sorted((TASKS / "done").glob("*.md"), key=lambda f: f.name, reverse=True) if (TASKS / "done").exists() else []
|
||||
if done:
|
||||
return [done[0]]
|
||||
failed = sorted((TASKS / "failed").glob("*.md"), key=lambda f: f.name, reverse=True) if (TASKS / "failed").exists() else []
|
||||
return [failed[0]] if failed else []
|
||||
return [f for f in completed_files() if identifier.lower() in f.name.lower()]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
for d in ("done", "failed"):
|
||||
(TASKS / d).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
identifier = sys.argv[1] if len(sys.argv) > 1 else ""
|
||||
matches = find_matches(identifier)
|
||||
|
||||
if not matches:
|
||||
if identifier:
|
||||
print(f"No task matches `{identifier}`. Try `list` to see what's available.")
|
||||
else:
|
||||
print("No completed tasks yet.")
|
||||
return
|
||||
|
||||
if len(matches) == 1:
|
||||
print(format_result(matches[0]))
|
||||
return
|
||||
|
||||
# Multiple matches — list for user to pick
|
||||
print(f"Multiple tasks match `{identifier}`:\n")
|
||||
for f in matches:
|
||||
m = FILENAME_RE.match(f.name)
|
||||
slug = m.group(2) if m else f.stem
|
||||
ts = m.group(1) if m else ""
|
||||
print(f"- `{slug}` ({ts}, {f.parent.name})")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user